Page 1 of 3 123>
Topic Options
#146894 - 2005-09-01 12:19 AM KiXgolf: Happy Numbers - Public Coding
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Gentlemen, please post your code!
_________________________
There are two types of vessels, submarines and targets.

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, my best code, the 91 one:
Code:

Function A($)
do
while $
$A = $A - -left($,1) * left($,1)
$ = right($,~)
loop
$ = $A
$A = $ = 1
until $ < 9
EndFunction



and then the last with the proper name and announced 119:
Code:

Function HappyNumbers($)
do
dim $t
while $
$t = $t + 1 * left($,1) * left($,1)
$ = right($,~)
loop
$ = $t
until $ < 9
$HappyNumbers = $ = 1
EndFunction



Edited by Lonkero (2005-09-01 12:27 AM)
_________________________
!

download KiXnet

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, can you post that code of shawn's?
_________________________
!

download KiXnet

Top
#146897 - 2005-09-01 12:27 AM Re: KiXgolf: Happy Numbers - Public Coding
Howard Bullock Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
Quote:

KiXGolf Score = 0




that's low!
_________________________
!

download KiXnet

Top
#146899 - 2005-09-01 12:30 AM Re: KiXgolf: Happy Numbers - Public Coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
The 107:

Code:

Function A($)

DIM $i

Do
$a=0
Do
$i=$ mod 10
$i=$i*$i
$a=$a+$i
$=$/10
Until $=0
$=$a
Until $=4 or $=1

$A=iif($=1,1,0)


EndFunction

_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#146900 - 2005-09-01 12:31 AM Re: KiXgolf: Happy Numbers - Public Coding
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Shawn is camping, thus I am posting the code on his behalf. I have verified the code on my computer, though, couldn't help but to look how he accomplished his feat.
Code:

Function A($)

while $
$a = $ mod 10 * ($ mod 10) + $a
$ = $ / 10
loop

if $a > 4
$a = a($a) = 1
;endif

EndFunction


And the score is as follows:
Code:

KiXtart
KiXtart Version = 4.51 Beta 1
KiXGolf Script = kixgolf_happy_numbers.KIX

Computer
OS = Windows XP Professional
CPU = Intel(R) Xeon(TM) CPU 3.06GHz
Speed = 3056 MHz
Memory = 2046 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Happy Numbers
Processing Start = 2005/08/31 18:12:38.577
Processing End = 2005/08/31 18:12:38.608
Duration = 0000/00/00 00:00:00.030
# Tests Run = 57
# Tests Passed = 57
# Tests Failed = 0
Result = passed
KiXGolf Score = 76

Thank you for participating in KiXtart Golf!

_________________________
There are two types of vessels, submarines and targets.

Top
#146901 - 2005-09-01 12:37 AM Re: KiXgolf: Happy Numbers - Public Coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
You guys gave me some ideas: 88

Code:

Function A($)

DIM $i

Do
$a=0
Do
$i=$ mod 10
$a=$a+$i*$i
$=$/10
Until $=0
$=$a
Until $<5

$A=$=1

EndFunction



Anyone can explain the $a=$=1 part???
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#146902 - 2005-09-01 12:42 AM Re: KiXgolf: Happy Numbers - Public Coding
jtokach Offline
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
#146903 - 2005-09-01 12:45 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
iif is evaluated kinda odd.
the true and false expressions are calculated before the if part kicks in.
thus, it is infinite loop you got there.
_________________________
!

download KiXnet

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
pat, I removed the dim line from your code and moved the $a = $ = 1 up a bit and got 80:
Code:

Function A($)
Do
Do
$a=$a + $ mod 10 * ($ mod 10)
$=$/10
Until $=0
$=$a
$A=$=1
Until $<5
EndFunction



$=1 you know, it's evaluation.
$=1 returns true (or 1) if $ equals 1. otherwise it returns false (or 0).

thus $A = $ = 1 resets $A to zero always except when $A should return 1 (happy number).
_________________________
!

download KiXnet

Top
#146905 - 2005-09-01 12:49 AM Re: KiXgolf: Happy Numbers - Public Coding
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
makes sense. How about the voodoo crap you guys are using? $a = a($a) = 1 ???
_________________________
-Jim

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

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
not voodoo, it's golfer language. or lonkenizer syntax.
however you wanna put it
_________________________
!

download KiXnet

Top
#146907 - 2005-09-01 12:55 AM Re: KiXgolf: Happy Numbers - Public Coding
maciep Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
so clever crap you boys.
I never came up with the mod 10.
I thought about it and tested some scenarios but my head never got there.

and that lacking endif.
brilliant!
_________________________
!

download KiXnet

Top
#146910 - 2005-09-01 01:00 AM Re: KiXgolf: Happy Numbers - Public Coding
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

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

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Just did a little testing on Shawn's code...2 is an unhappy number, right?
Top
#146912 - 2005-09-01 01:11 AM Re: KiXgolf: Happy Numbers - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I was thinking the same.
_________________________
!

download KiXnet

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
and yes.
first happy numbers go like:
1, 7, 13, 19, 23
_________________________
!

download KiXnet

Top
Page 1 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 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.152 seconds in which 0.104 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