Page 2 of 3 <123>
Topic Options
#146914 - 2005-09-01 01:22 AM Re: KiXgolf: Happy Numbers - Public Coding
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is my HappyNumbers code...

Code:

Function HappyNumbers($)
Do
ReDim $z,$a
Do
$z=$ mod 10
$a=$a+$z*$z
$=$/10
Until $=0
$=$a
Until $=1 | $=4
$HappyNumbers=$<>4
EndFunction


...For a longname score of 116

And...
Code:
Function A($)
Dim $z
Do
Do
$z=$ mod 10
$a=$a+$z*$z
$=$/10
Until $=0
$=$a $a=0
Until $=1 | $=4
$a=$<>4
EndFunction



...for a short name score of 93.

Top
#146915 - 2005-09-01 01:31 AM Re: KiXgolf: Happy Numbers - Public Coding
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
yeah, i had that code checking for 1 or 4 as well. then i was like wait a second, 2,3 and 4 are all unhappy...i should be able to use that to my advantage somehow.
Top
#146916 - 2005-09-01 01:41 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, jens.
shawn's code does not work for 2.
is this acceptable as it was not in the test suite?
_________________________
!

download KiXnet

Top
#146917 - 2005-09-01 01:49 AM Re: KiXgolf: Happy Numbers - Public Coding
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I'd say it doesn't since it does not properly evaluate all happy and unhappy numbers.
Top
#146918 - 2005-09-01 01:54 AM Re: KiXgolf: Happy Numbers - Public Coding
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Jim, I had a version that used SubStr too. It's funny how all of the working solutions are so similar.
Top
#146919 - 2005-09-01 02:10 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
chris, think that's because the task was so simple.
there was not so much to alter your way with.

I still love the right($,~) tweak though.
or the fact that preceding string with minus sign makes kixtart think it's a number.
think that's a bug though.


and then we come back to realize that all the great minds think alike.
thus, the solutions of ours had to be similar
_________________________
!

download KiXnet

Top
#146920 - 2005-09-01 02:14 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, I think shawns code should be accepted as these things has happened before and we have always blamed jens on it

so, I think shawn and maciep should both have points.
maciep for shorters actually working code and shawn for shortest code that passed the testsuite.

and to make everyone happy, the direct ini read did not come even close to our results.
so I would call the scores LOW.
_________________________
!

download KiXnet

Top
#146921 - 2005-09-01 03:41 AM Re: KiXgolf: Happy Numbers - Public Coding
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Here's mine...

Code:
 
Function A($)
do
do
$a=$a + ($ mod 10) * ($ mod 10)
$=$/10
until $=0
$=$a
$a=iif($=1,1,0)
until $<10 | $a
Endfunction


Top
#146922 - 2005-09-01 03:57 AM Re: KiXgolf: Happy Numbers - Public Coding
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I knew there had to be a way to get rid some of those parenthesis

-2 on my score... to 93.
-1 for the $=4... to 92

Code:
 
Function A($)
do
do
$a=$ mod 10 * ($ mod 10) + $a
$=$/10
until $=0
$=$a
$a=iif($=1,1,0)
until $=4 | $a
Endfunction



Edited by Allen (2005-09-01 04:13 AM)

Top
#146923 - 2005-09-01 04:12 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
replace "until $<10 | $a" with "until $<10" or even "until $<9"
_________________________
!

download KiXnet

Top
#146924 - 2005-09-01 04:26 AM Re: KiXgolf: Happy Numbers - Public Coding
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
With suggestions from Lonk... and stealing ideas from others... able to knock off 15 strokes, in no time flat... I know I'm not up there with the leaders, but still fun to see the strokes coming off...

80

Code:
 Function A($)
do
do
$a=$ mod 10 * ($ mod 10) + $a
$=$/10
until $=0
$=$a
$a=$=1
until $<9
Endfunction



Top
#146925 - 2005-09-01 05:02 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I don't like that new not operator.
I know it's "binary" or bitwise, whatever that means.
what we really would need is logical not.

until !$ ; until $ is no more.
_________________________
!

download KiXnet

Top
#146926 - 2005-09-01 05:14 AM Re: KiXgolf: Happy Numbers - Public Coding
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I think you do have that Lonk. It costs 3 strokes "NOT".
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#146927 - 2005-09-01 12:58 PM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeah... guess you are right.
_________________________
!

download KiXnet

Top
#146928 - 2005-09-01 07:02 PM Re: KiXgolf: Happy Numbers - Public Coding
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
I'm thinking the next round is going to be far more competitive now that we all know these little tricks.
1*(str) vs. -(str) ;Brilliant
MOD vs. substr,left,right ;Brilliant
$A=$=1 ;Brilliant, had no idea this was even possible in kix

I've got issues with if w/o endif though. Seems more of poor man's hack than a clever solution.

To Chris' point, it is amazing how similar the code is. Late yesterday, I started working on another recurisive solution that looks like a bastardized frankenstein of the MOD flavored code and the left,right,substr code. Couldn't bring it together though.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#146929 - 2005-09-01 07:12 PM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.
ja, you go ahead and use bastardized.
lonkenized is trademarked already.

what comes to the tricks...
well, over half of the racers already knew them.
just somehow half of the half just had forgotten some of them (including me )
_________________________
!

download KiXnet

Top
#146930 - 2005-09-01 07:39 PM Re: KiXgolf: Happy Numbers - Public Coding
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Fine then, here's the lonkenized, post bastardization impressionist version of my crappy code: (a.k.a. Old School)
Score=97
Code:
Function A($)
Dim $i,$j
For $i = 1 To 9
$j=-substr($,$i,1)
$a=$a+$j*$j
Next
If $>5
$=A($a)
EndIf
$a=$=1
EndFunction



It screams for $a+=$j^2
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#146931 - 2005-09-01 08:34 PM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, so do I.

2 things missing in kix...
_________________________
!

download KiXnet

Top
#146932 - 2005-09-02 04:57 AM Re: KiXgolf: Happy Numbers - Public Coding
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
According ot the rules
Quote:


============
Test program
============


A test program is provided to help screen entries and to provide the Golf Score.
Any program that passes the test program can be submitted. If you are surprised that your solution passed the test program, please submit it anyway! That will help me identify bugs in the test program.




Thus, one can consider the exclusion of e.g. 2, 3, 4 as test cases a bug in the test program. I have also checked with other programming contest sites and the updating of test cases is quite common. I therefore see no reason not to update the test cases in the package. If a solution indeed miscategorizes a number, then is is not solving the problem at hand.

An updated version of the test cases is available at http://s91376351.onlinehome.us/kixtart/kixgolf_happy_numbers.zip

I will update the rules accordingly for the next tournament to explicitly state that the test suite can be amended at any time to provide a greater variety of test cases.
_________________________
There are two types of vessels, submarines and targets.

Top
#146933 - 2005-09-02 03:10 PM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, you're so juridic...

thanks for the response.
gladly I don't have to consider what to do with the private round points then...
_________________________
!

download KiXnet

Top
Page 2 of 3 <123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 533 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.123 seconds in which 0.078 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org