Top Challenge Entrants
1
jaytea
587 2
[Znork]
303 3
urza
297 4
Ag2X
288 5
dr_Eamer
255 6
Albie
199 7
Chessnut
197 8
A Noniem
194 9
zzattack
186 10
Kol
185 11
m910q
168 12
Sephiroth
115 13
Auron956
114 14
patje
114 15
chid
110 16
Ohad2121
92 17
SkorpSSS
87 18
DixrouE
84 19
Suchorski
83 20
^Vampire^
74
Challenge: Smallest $ishappy number
Start: August 9th 2009
End: August 15th 2009
Results
Another very successfull challenge. Across both regex and non-regex sections there are a total of
70 entries of which were valid:
38 non-regex and 26 regex.
Once again we have a 3-way tie! Congratulations to the winners; jaytea, zzattack and Ohad2121.
Winner! jaytea (105 bytes!)
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) \\ 4 /
}
return $and(1,$v1)
Winner! zzattack (105 bytes!)
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) \\ 4 /
}
return $and($v1,1)
Winner! Ohad2121 (105 bytes!)
alias ishappy {
:a
tokenize 32 $mid($1,2) $calc($left($1,1)^2+$2)
if !$2 && $1 < 9 return $count(1,$1)
goto a
Non regex entries Top entries:
1
jaytea
105 bytes
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) \\ 4 /
}
return $and(1,$v1)
zzattack
105 bytes
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) \\ 4 /
}
return $and($v1,1)
Ohad2121
105 bytes
alias ishappy {
:a
tokenize 32 $mid($1,2) $calc($left($1,1)^2+$2)
if !$2 && $1 < 9 return $count(1,$1)
goto a
2
Kol
106 bytes
alias ishappy {
while $1 > 5 tokenize 1 $calc($left($1,1)^2+$mid($1,2,1)^2+$mid($1,3)^2)
return $isbit(1,$1)
3
Chessnut
107 bytes
alias k inc %t $calc($mid($v1,$1,1)^2)
alias ishappy {
%t = $1
while %t > 6 {
%t =
k 1
k 2
k 3
}
return $isbit(1,%t)
m910q
107 bytes
alias ishappy {
$iif($1,)
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) > 4 /
return $count($v1,1)
urza
107 bytes
alias ishappy {
if ($1) /
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) > 4 /
return $count($v1,1)
4
SniperMS
109 bytes
alias ishappy {
while $1 > 4 tokenize 1 $calc($mid($1,1,1)^2+$mid($1,2,1)^2+$mid($1,3,1)^2)
return $count($1,1)
5
visionz
110 bytes
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) !isin 401 !
}
return $and($v1,1)
^Vampire^
110 bytes
alias ishappy {
while ($calc($left($1,1)^2+$mid($1,2,1)^2+$mid($1,3)^2) > 9) tokenize 1 $v1
return $count($v1,1)
A Noniem
110 bytes
alias ishappy {
if $1 {
while $calc($left($v1,1)^2+$mid($v1,2,1)^2+$mid($v1,3)^2) !isin 16 {
}
}
return $and($v1,1)
6
dr_Eamer
111 bytes
alias ishappy {
:x
if $1 < 5 return $count($1,1)
:0
tokenize 32 $right($1,-1) $calc($2 + $left($1,1) ^2) 0 x
goto $3
7
[Znork]
112 bytes
alias s %s = $calc($left(%s,1)^2+$mid(%s,2,1)^2+$mid(%s,3)^2)
alias ishappy {
%s = $1
s
s
s
s
s
s
return $iif(%s = 1,1,0)
8
snabbi
117 bytes
alias ishappy {
%x = $1
:4
var %a %x,%x,%n
if %a < 5 return $iif(%a = 1,1,0)
:%n
inc %x $calc($mid(%a,%n,1)^2)
inc %n
goto %n
9
mQ
120 bytes
alias {
%x =
%j = 3
while %j {
%x = $calc(%x +$mid(%l,%j,1)^2)
dec %j
}
%l = %x
}
alias ishappy {
%l = $1
return $iif(%l = 1,1,0)
10
p4r4ll4x
121 bytes
alias ishappy {
while $1 !isin 014 {
inc %b $calc($mid($1,%x,1)^2)
if %x > 5 {
tokenize 3 %b
%b =
%x =
}
inc %x
}
return $and($1,1)
11
Suchorski
122 bytes
alias ishappy {
while $1 !isin 014 {
%° = 5
%¢ =
while %° {
inc %¢ $calc($mid($1,%°,1)^2)
dec %°
}
tokenize 3 %¢
}
return $and($1,1)
12
Albie
124 bytes
alias ishappy {
%: = $1
goto %:
:4
:0
%: = 0
:1
return %:
:%:
%% =
while %: {
inc %% $calc((%: % 10)^2)
%: = $left(%:,-1)
}
%: = %%
goto %:
patje
124 bytes
alias ishappy {
%a = $1
goto %a
:1
return 1
:0
:4
return 0
:%a
%d = 3
%i =
while %d {
inc %i $calc($mid(%a,%d,1)^2)
dec %d
}
%a = %i
goto %a
13
DixrouE
125 bytes
alias ishappy {
$iif($1,)
while ($calc($mid($v1,1,1)^2+$mid($v1,2,1)^2+$mid($v1,3,1)^2) != 1) if ($v1 isin 04) return 0
return 1
14
StruC
126 bytes
alias _ inc %x $calc($mid(%r,$1,1)^2)
alias ishappy {
%r = $1
:b
%x =
_ 1
_ 2
_ 3
if $len(%x) = 1 return $iif(%x = 1,1,0)
%r = %x
goto b
15
bamaboy
128 bytes
alias ishappy {
%a = $1
goto %a
:4
%a = 0
:1
:0
return %a
:%a
%a = $calc($i(1) $i(2) $i(3) $i(4))
goto %a
}
alias i return $mid(%a,$1,1) ^2+
eXonyte
128 bytes
alias ishappy {
%x = $1
while (%x !isin 014) %x = $calc($q(1) $q(2) $q(3) $q(4))
return $and(1,%x)
}
alias q return $mid(%x,$1,1) ^2+
16
chid
131 bytes
alias ishappy {
:p
if $pos(41,$1) || !$1 {
return $(},$v1)
}
%i = 4
%s =
while %i {
inc %s $calc($mid($1,%i,1)^2)
dec %i
}
tokenize 2 %s
goto p
17
Daveoh
134 bytes
alias ishappy {
%z = $1
:a
inc %o $calc($mid(%z,-1)^2)
%z = $left(%z,-1)
if !%z {
%z = %o
%o =
if %z isin 04 return 0
if %z = 1 return 1
}
goto a
18
jos
137 bytes
alias ishappy {
%t = 6
%c = $1
while %t {
%p =
while %c {
inc %p $calc($left(%c,1)^2)
%c = $mid(%c,2,2)
}
%c = %p
dec %t
if %p = 1 return 1
}
return 0
19
Auron956
138 bytes
alias ishappy {
while $1 !isin 01;4 {
var %x 1,%t
while $mid($1,%x,1) != $a {
inc %t $calc($v1 ^2)
inc %x
}
tokenize 1 %t
}
return $replace($1,4,0)
20
Sephiroth
140 bytes
alias ishappy {
%+ = $1
%r = return
while %+ {
inc %o $calc($mid(%+,-1)^2)
%+ = $left(%+,-1)
if !%+ {
%+ = %o
%o =
if %+ = 4 %r 0
if %+ = 1 %r 1
}
}
%r 0
bindi
140 bytes
alias ishappy {
%z = $1
%r = return
while %z {
inc %o $calc($mid(%z,-1)^2)
%z = $left(%z,-1)
if !%z {
%z = %o
%o =
if %z = 4 %r 0
if %z = 1 %r 1
}
}
%r 0
21
Jigsy
146 bytes
alias ishappy {
%0 = $1
:x
$iif(%0 = 1,return 1)
%1 = 4
while %1 {
inc %2 $calc($mid(%0,%1,1)^2)
dec %1
}
%0 = %2
%2 =
$iif(%0 = $1 || %0 = 4,return 0)
goto x
Champagne
146 bytes
alias ishappy {
%a = $1
%b = 6
while %b {
%c =
while %a {
%d = %a % 10
%c = $calc(%c +%d ^2)
%a = $calc((%a -%d)/10)
}
%a = %c
dec %b
}
return $iif(%a = 1,1,0)
22
Srankie
149 bytes
alias ishappy {
%l =
while %o != 1 {
var %n $iif(%o,%o,$1),%a 1,%o
while $mid(%n,%a,1) > ! {
%o = $calc($v1 ^2+%o)
inc %a
}
inc %l
if %l > 9 return 0
}
return 1
23
user007
157 bytes
alias ishappy {
while !$istok(%n,$1,32) {
var %o,%n = %n $1,%x = 1
while $mid($1,%x,1) >= 0 {
%o = $calc(%o + $v1 ^2)
inc %x
}
tokenize 1 %o
}
return $iif(%o = 1,1,0)
24
Shinigami
168 bytes
alias ishappy {
%1 = $1
%s =
:a
%a = 1
while %a <= $len(%1) {
%s = $calc(%s + $mid(%1,%a,1) ^ 2)
if %a = $v2 && $len(%s) > 1 {
%1 = %s
%s =
goto a
}
inc %a
}
return $iif(%s = 1,1,0)
}
Ryan-|
168 bytes
alias ishappy {
:D
var %a,%r return,%b tokenize 1
while $1 != 1 {
while $1 {
inc %a $calc($left($1,1)^2)
%b $mid($1,2)
}
%b $calc(%a)
if $1 = 1 %r 1
if $1 isin 04 %r 0
goto D
}
%r 1
25
WorldDMT
170 bytes
alias ishappy {
while !$istok(014,%r,2) {
var %x $iif(%r,$v1,$1),%y $len(%x),%z
while (%y) var %z %z $mid(%x,$v1,1) $+ ^2 +,%y %y - 1,%r $calc(%z)
}
return $iif(%r = 1,1,0)
}
26
Natdhib
179 bytes
Alias ishappy return $iif($S($1) != 1,0,1)
Alias S {
var %T = 1
while (%T <= $len($1)) {
var %U = $mid($1,%T,1) ^ 2, %V $calc(%V + %U)
inc %T
}
return $iif($len(%V) = 1,%V,$ishappy(%V))
}
27
[Mosh]
276 bytes
alias ishappy {
var %d 1,%a $1,%b $1
while %a != %s && %a != 1 {
var %c %b,%z 1,%1 $mid(%a,1,1),%2 $mid(%a,2,1),%3 $mid(%a,3,1),%a $calc(%1 ^2+%2 ^2+%3 ^2)
while %z < %d {
if %y [ $+ [ %z ] ] = %a return 0
inc %z
}
var %y $+ %d %a
inc %d
}
var %c %b
if %a = 1 return 1
if %a = %c return 0
}
28
Alan
594 bytes
alias ishappy return $iif($istok($replace(1 7 c d 19 g 28 31 32 44 49 68 70 79 82 86 91 94 97 c0 c3 c9 129 d0 d3 d9 167 176 188 1f 192 1e 203 208 219 226 g0 2a g9 262 2b 280 291 2e 301 302 3c 3d 319 320 326 329 331 338 3h a2 a5 a7 a8 376 379 383 386 391 392 397 404 409 440 446 464 469 478 487 4f 496 5a 5h 5b h5 h6 608 617 622 6g b2 b5 b7 b8 644 649 653 655 6h 665 671 673 680 683 694 700 709 716 7a 739 748 761 7b 784 7f 7e 802 806 818 820 833 8a 847 860 8b 874 881 888 899 f1 f4 f7 9c 912 9d 921 9g e1 e2 e7 940 946 964 970 973 989 998 c00,a,36,b,63,c,10,d,13,e,93,f,90,g,23,h,56),$1,9),1,0)
29
PhireCoder
901 bytes
/* $ishappy - By PhireCoder
This alias will return 1 if $1 is a happy number such as 1 of the folling:
1710131923283132444968707982869194971001031091291301331391671761881901921932032082192262302362392622632802912933013023103133193203263293313383563623653673683763793833863913923974044094404464644694784874904965365565635655666086176226236326356376386446496536556566656716736806836947007097167367397487617637847907938028068188208338368478608638748818888999019049079109129139219239319329379409469649709739899981000
And it will return 0 is it is not a happy number :)
It uses a form of $read simular to that in this example code:
return $findtok($read($script,3),$1,0,5)
but just slightly different :)
Hope you like it! and hope I win :)
*/
alias ishappy $read($script,6)
Invalid entries:
TheInCircuit
28 bytes
* Failed on tests: 0 2 3 4 5 6 10 11 14 18 ...
alias ishappy return $r(0,1)
Jango
136 bytes
* Failed on tests: 0 goes into an endless loop
alias ishappy {
var %e $1
:o
if (%e == 4) return 0
var %e $calc($mid(%e,1,1)^2 + $mid(%e,2,1)^2 + $mid(%e,3,1)^2)
if (%e != 1) goto o
return 1
Parkair
422 bytes
* Failed on tests: uses /halt and crashes mirc
alias ishappy {
var %number = $1, %return = null, %numberstore
if (%number == 1) { return 1 | halt }
elseif (%number <= 0) { halt | return Invalid input detected. }
while (%return == null) {
var %x = 1
while (%x != $len(%number)) { var %numberstore = %numberstore $left(%number,%x) $+ ^2 + | inc %x }
if ($calc(%numberstore) == 1) { return 1 | halt }
elseif ($calc(%numberstore) == %number) { return 0 | halt }
unset %numberstore
}
}
Regex entries Top entries:
1
zzattack
83 bytes
alias ishappy {
if $1 {
while $calc($regsubex($v1,//g,^2+)) \\ 4 /
}
return $and($v1,1)
jaytea
83 bytes
alias ishappy {
if $1 {
while $calc($regsubex($v1,//g,^2+)) \\ 4 /
}
return $and(1,$v1)
2
Kol
84 bytes
alias ishappy {
if $1 {
while $calc($regsubex($v1,//g,^2+)) > 5 /
}
return $isbit(1,$v1)
3
Chessnut
86 bytes
alias ishappy {
if $1 {
while $calc(0 $regsubex($v1,//g,^2+)) > 6 /
}
return $isbit(1,$v1)
4
urza
90 bytes
alias ishappy {
if ($1) /
while $calc($regsubex($v1,/(.)/g,\1^2+)) > 4 /
return $count($v1,1)
5
SniperMS
91 bytes
alias ishappy {
while $1 > 4 tokenize 1 $calc($regsubex($1,/(.)/g,+\t^2))
return $count($1,1)
Ohad2121
91 bytes
alias ishappy {
:a
tokenize 3 $calc($regsubex($1,//g,^2+))
if $1 < 9 return $count(1,$1)
goto a
6
A Noniem
92 bytes
alias ishappy {
if $1 {
while $calc($regsubex($v1,/\B/g,^2+)^2) !isin 16 {
}
}
return $and($v1,1)
7
Albie
93 bytes
alias ishappy {
%: = $1
goto %:
:4
%: = 0
:0
:1
return %:
:%:
%: = $calc($regsubex(%:,//g,^2+))
goto %:
8
Suchorski
95 bytes
alias ishappy {
while $1 !isin 014 tokenize 3 $calc($regsubex($1,/(.)/g,\t^2+))
return $and($1,1)
^Vampire^
95 bytes
alias ishappy {
while ($calc($regsubex($1,/(.)/g,\1^2+)) > 9) tokenize 1 $v1
return $regex($v1,1)
poste9
95 bytes
alias ishappy {
while $1 !isin 014 tokenize 1 $calc($regsubex($1,/(.)/g,\t^2+))
return $and($1,1)
theafien
95 bytes
alias ishappy {
while $calc($regsubex($v1 $1,/(.)( $1)?/g,\t^2+)) !isin 014 {
}
return $and($v1,1)
9
OokMP3
96 bytes
alias ishappy {
if $1 {
while $calc($regsubex($v1,/(\d)/g,+\t^2)) > 4 {
}
}
return $iif($v1 = 1,1,0)
}
patje
96 bytes
alias ishappy {
while $calc($regsubex($1,//g,^2+)) !isin 014 tokenize 1 $v1
return $calc($v1 % 2)
10
eXonyte
99 bytes
alias ishappy {
%x = $1
while (%x !isin 014) %x = $calc($regsubex(%x,/(.)/g,\1^2+))
return $and(1,%x)
}
11
chid
101 bytes
alias ishappy {
:D
if $pos(41,$1) || !$1 {
return $(},$v1)
}
tokenize 2 $calc($regsubex($1,//g,^2+))
goto D
[Znork]
101 bytes
alias s %s = $calc($regsubex(%s,/([0-9])/g,\t^2+))
alias ishappy {
%s = $1
s
s
s
s
s
s
return $iif(%s = 1,1,0)
12
Auron956
102 bytes
alias ishappy {
while $1 !isin 01;4 tokenize 1 $calc($regsubex($1,/(.)/g,\t^2+))
return $replace($1,4,0)
13
DixrouE
109 bytes
alias ishappy {
$iif($1,)
while ($calc($regsubex($v1,/([0-9])/g,\1^2+)) != 1) if ($v1 isin 04) return 0
return 1
Jeffreims
109 bytes
alias ishappy {
%x = $1
while %x > 2 && %x != 4 {
%x = $calc($regsubex(%x,/(?)/g,\t^2+))
}
return $iif(%x = 1,1,0)
14
TheInCircuit
113 bytes
alias ishappy {
while %x !isin 04 {
var %x $calc($regsubex($iif(%x,%x,$1),/(.)/g,\1^2+))
if %x = 1 return 1
}
return 0
15
snabbi
115 bytes
alias ishappy {
%x = $1
:4
var %a %x,%x,%n
if %a < 5 return $regex(%a,/1/)
:%n
inc %x $calc($mid(%a,%n,1)^2)
inc %n
goto %n
16
bindi
116 bytes
alias ishappy {
%x = $1
%r = return
while $calc($regsubex(%x,/(.)/g,\1^2+)0) {
%x = $v1
if %x = 4 %r 0
if %x = 1 %r 1
}
%r 0
17
StruC
122 bytes
alias _ inc %x $calc($mid(%r,$1,1)^2)
alias ishappy {
%r = $1
:b
%x =
_ 1
_ 2
_ 3
if $len(%x) = 1 return $regex(%x,1)
%r = %x
goto b
18
Sephiroth
156 bytes
alias ishappy {
%x = $1
while $regex(%x,/(\d)/g) {
%o = $v1
%x =
while %o {
inc %x $calc($regml(%o)^2)
dec %o
}
if ($istok(014,%x,2)) break
}
return $iif(%x = 1,1,0)
Invalid entries:
Srankie
62 bytes
* Failed on tests: 1 3 7 8 10 11 13 14 16 18 ...
alias ishappy return $iif($regsubex($str(@,$r(1,2)),/@/,),1,0)