#146897 - 2005-09-01 12:27 AM
Re: KiXgolf: Happy Numbers - Public Coding
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
KiXtart KiXtart Version = 4.50 KiXGolf Script = kixgolf_happy_numbers.kix
Computer OS = Windows XP Professional CPU = Intel Pentium Model 13 Speed = 1798 MHz Memory = 1024 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXtart Golf Score Tournament = KiXtart Golf: Happy Numbers Processing Start = 2005/08/31 18:07:55.518 Processing End = 2005/08/31 18:07:55.548 Duration = 0000/00/00 00:00:00.030 # Tests Run = 57 # Tests Passed = 57 # Tests Failed = 0 Result = passed KiXGolf Score = 84
Thank you for participating in KiXtart Golf! Code:
Function A($)
do dim $y do $A=$ mod 10 $=$/10 $y=$A*$A+$y until $=0 $=$y until $<7 $A=$=1
EndFunction KiXtart KiXtart Version = 4.50 KiXGolf Script = kixgolf_happy_numbers.kix
Computer OS = Windows XP Professional CPU = Intel Pentium Model 13 Speed = 1798 MHz Memory = 1024 MB
KiXGolf Scoring Engine Scoring Engine = 3.0.3
KiXtart Golf Score Tournament = KiXtart Golf: Happy Numbers Processing Start = 2005/08/31 18:12:32.727 Processing End = 2005/08/31 18:12:32.767 Duration = 0000/00/00 00:00:00.040 # Tests Run = 57 # Tests Passed = 57 # Tests Failed = 0 Result = passed KiXGolf Score = 84
Thank you for participating in KiXtart Golf! Code:
Function A($y)
dim $ do $A=$y mod 10 $y=$y/10 $=$A*$A+$ until $y=0
$A=$=1 if $>6 $A=A($) EndFunction
Edited by Howard Bullock (2005-09-01 12:30 AM)
|
|
Top
|
|
|
|
#146902 - 2005-09-01 12:42 AM
Re: KiXgolf: Happy Numbers - Public Coding
|
jtokach
Seasoned Scripter
   
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
107
Code:
Function A($) Dim $i,$j For $i = 1 To 4 $j=1*substr($,$i,1) $a=$a+$j*$j Next ;$=IIF($>5,A($a),IIf($=1,$,0)) If $>5 $=A($a) EndIf $a=IIf($=1,$,0) EndFunction
Can someone please explain how this "$a = a($a) = 1" works? And why my remmed out IIF causes a stack overflow?
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
|
Top
|
|
|
|
#146907 - 2005-09-01 12:55 AM
Re: KiXgolf: Happy Numbers - Public Coding
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Here's my code with a score of 80
Code:
Function A($) do while $ $A = $A + $ mod 10*($ mod 10) $=$/10 loop $=$A $A=$=1 until $<5 EndFunction
And here is my "I can't believe this even runs" code with a score of 79
Code:
Function A($) $A=$=1 if $>4 while $ $A = $A + $ mod 10*($ mod 10) $=$/10 loop $A= A($A) EndFunction
|
|
Top
|
|
|
|
#146908 - 2005-09-01 12:55 AM
Re: KiXgolf: Happy Numbers - Public Coding
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
this is fairly straight forward.
$a = a($a) = 1
KiX evalutes right to left
a($a) is a recursive call of the function
it returns a value
this could be written like but the parens are not necessary. $a = (a(a$)=1)
This basicly says is $a(a$) equal to 1. If not send zero through the next equal sign to the left most $a. If a($) is 1 then 1=1 which is true and 1 is then passed.
|
|
Top
|
|
|
|
#146910 - 2005-09-01 01:00 AM
Re: KiXgolf: Happy Numbers - Public Coding
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I finally got the MOD for the first digit but never thought to use it again for retrieving the same value to square it.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|