Create a program that, given an integer 0 through 999,999, does the "4 is magic" transformation. If you don't know what that is, this is it:
Take the number written out in English and count the number of letters (i.e. 21 is "twenty-one" is 9 letters, 102 is "one hundred two" is 13 letters, 9999 is "nine thousand nine hundred ninety-nine" is 33 letters).
If the result is 4, output "4 is magic." and exit.
Else, output "(original number) is (result)." and repeat step 1 with the result.
31 is 9. 9 is 4. 4 is magic. -70% bonus if you actually display the number-words instead of the numbers.
Deadline October 5, 2014, 1:00 AM EST
If any further clarification is needed, contact me. I'll try to make your troubles disappear.
Ruby
Rank
User
Size
Date
Code
1
Juju
548-70%=164.4
9/23/2014 6:25:12 PM
Spoiler For Spoiler:
def w(n) case n when 0..19 ["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"][n] when 20..99 ["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"][n/10-2]+(n%10==0?"":" "+w(n%10)) when 100..999 w(n/100)+" hundred"+(n%100==0?"":" "+w(n%100)) when 1000..999999 w(n/1000)+" thousand"+(n%1000==0?"":" "+w(n%1000)) end end a=gets.to_i while a!=4 p w(a)+" is "+w(a=w(a).delete(" ").length)+"." end p"four is magic."
Golfscript
Rank
User
Size
Date
Code
1
JWinslow23
360-70%=108
10/4/2014 9:37:27 AM
Spoiler For Spoiler:
~{.20<{.12>["zero""one""two""three""four""five""six""seven""eight""nine""ten""eleven""twelve""thir""four""fif""six""seven""eigh""nine"]@="teen"@*+}{.100<{.10/2-["twen""thir""for""fif""six""seven""eigh""nine"]{"ty"+}%\=\10%a" "\++}{.1000<{.100/a" hundred "+\100%a+}{.1000/a" thousand "+\1000%a+}if}if}if" zero"%""+}:a;{.4=}{a." "/""+," is "\.n\}until" is magic"
Python
Rank
User
Size
Date
Code
1
Ivoah
962-70%=288.6
9/26/2014 6:32:23 PM
Spoiler For Spoiler:
import sys a = {1:' one',2:' two',3:' three',4:' four',5:' five',6:' six',7:' seven',8:' eight',9:' nine',10:' ten',11:' eleven',12:' twelve',13:' thirteen',14:' fourteen',15:' fifteen',16:' sixteen',17:' seventeen',18:' eighteen',19:' nineteen',20:' twenty',30:' thirty',40:' forty',50:' fifty',60:' sixty',70:' seventy',80:' eighty',90:' ninety',100:' hundred',1000:' thousand'} def b(n): if n<=20: if n==0:return 'zero' else:return a[n].strip() else: c='' for d,e in enumerate(str(n)): i=10**(len(str(n))-d-1) j=int(e) if i==1e5:c+=a[j]+a[100] elif i==1e4:c+=a[j*10] elif i==1e3: if c[-3:]=='ten'and j!=0:c=c[:-4]+a[j+10] else:c+=a[j] c+=a[1e3] elif i==100:c+=a[j]+a[100] elif i==10:c+=a[j*10] elif i==1: if c[-3:]=='ten'and j!=0:c=c[:-4]+a[j+10] else:c+=a[j] c=c.strip() return c n=sys.argv[1] while True: f=len(''.join(b(n).split())) print b(n),'is',b(f) n=f if f==4:print b(4),'is magic!';break
Check if a string is conveniently palindromic, and output 1 if it is and 0 if it isn't. This means that the char pairs () {} [] <> should be handled such that strings such as
p (a=gets.chop.upcase)==a.reverse.tr("[{(<>)}]","]})><({[")?1:0
TI-83+ BASIC
Rank
User
Size
Date
Code
1
JWinslow23
177
9/2/2014 5:43:43 PM
Spoiler For Spoiler:
" "+Ans+" ->Str1 Ans->Str3 "({[<)}]>->Str2 For(X,1,length(Str1 For(Y,1,4 sub(Str1,X,1 5(Ans=sub(Str2,Y,1))+(Ans=sub(Str2,Y+4,1 If Ans sub(Str1,1,X-1)+sub(Str2,Y+Ans-1,1)+sub(Str1,X+1,length(Str1)-X->Str1 End End Str1 For(X,1,length(Ans)-1 sub(Ans,2X,1)+Ans End Str3=sub(Ans,1,X
Nspire Lua
Rank
User
Size
Date
Code
1
Jens_K
145
9/4/2014 4:52:18 PM
Spoiler For Spoiler:
function cgc8(s) R=1 r="<>()[]{}/\\"l=s:len()for i=1,l do p=r:find(s:sub(i,i),1,1)or 0 p=p+p%2*2-1 q=l-i+1 R=p>0 and r:sub(p,p)~=s:sub(q,q)and 0 or R end print(R) end
I have no idea how to embed videos, so here you go.
A couple of amateur special effects that I made today. Nothing other than jump cuts and a tiny bit of speedup here and there. If I could just compress them a bit more, then I could have a bunch of ready-made vines!
Problem Make a program that, given an input as a string, outputs the (newline-separated) indexes of the string where the letters that make up the word "code" appear (one of each in order). For example, for input such as:
School is about to start! Be sure to do your homework!
the letters that make up the word "code" are marked by asterisks here:
School is about to start! Be sure to do your homework! ^ ^ ^ ^
(in that exact order) (search should be case-insensitive if possible) And the output would be:
2 4 38 49
(the positions of the characters in the string). Simply output ONLY 0 if such is impossible.
Deadline September 1, 2014, 1:00 AM EST
If any further clarification is needed, contact me. I will try to search for order. (honestly, nobody comments about the puns anymore )
Java
Rank
User
Size
Date
Code
1
3298
189
8/29/2014 12:16:14 PM
Spoiler For Spoiler:
class G{public static void main(String[]s){String o="";int p=0;for(char c:"code".toCharArray()){p=s[0].toLowerCase().indexOf(c,p);if(p<0){o="0";break;}o=o+(p+1)+"\n";}System.out.print(o);}}
2
pimathbrainiac
268
8/25/2014 6:57:57 PM
Spoiler For Spoiler:
import java.util.Arrays;public class C7{public static void main(String[] args){String s=Arrays.toString(args);int a,b,c,d;a=s.indexOf('c')-1;b=s.indexOf('o')-1;if(b>a){c=s.indexOf('d')-1;if(c>b){d=s.indexOf('e')-1;if(d>c){System.out.print(a+"\n"+b+"\n"+c+"\n"+d);}}}}}
function cgc7(s) i=0 repeat p=s:find(("c.*o.*d.*e"):sub(i*3+1),p)or 0 print(p)i=i+1 until p*(4-i)<1 end
2
Adriweb
104
8/26/2014 9:43:18 AM
Spoiler For Spoiler:
function y(s)t={}for a=1,4 do t[#t+1]=s:find(("code"):sub(a,a),t[#t])end print(#t<4 and 0 or table.concat(t,"\n"))end end
TI-83+ BASIC
Rank
User
Size
Date
Code
1
JWinslow23
50
8/26/2014 10:54:23 AM
Spoiler For Spoiler:
Input Str1 1 For(X,1,4 inString(Str1,sub("CODE",X,1),Ans If not(Ans ClrHome Disp Ans If not(Ans Return End
Axe
Rank
User
Size
Date
Code
1
JWinslow23
152
8/28/2014 9:43:23 AM
Spoiler For Spoiler:
"CODE"->Str1 input->M 0->A For(X,0,3) If inData({X+Str1},A+M) +A End !If ->A 4->X ClrHome End Disp A>Dec,i End
XTend
Rank
User
Size
Date
Code
1
3298
163
8/29/2014 12:16:14 PM
Spoiler For Spoiler:
class G{def static void main(String[]s){var o=""var p=0;for(c:"code".toCharArray){p=s.head.toLowerCase.indexOf(c,p)if(p<0){print(0)return}o=o+(p+1)+"\n"}print(o)}}
Haskell
Rank
User
Size
Date
Code
1
3298
174
8/29/2014 12:16:14 PM
Spoiler For Spoiler:
import Data.Char g i=putStr o where(_,o,_)=foldl h(i,"",0)"code" h(s,r,n)c=if t/=""then(tail t,r++(show m)++"\n",m)else(t,"0",m)where(d,t)=span((/=c).toLower)s;m=n+1+length d
Problem Make a program that, given an input as a number, outputs the program size as a word (i.e. SEVENTY-FIVE or ONE HUNDRED TWELVE or ONE THOUSAND ONE HUNDRED THIRTY-SEVEN), then the square of the sum of the digits of the input (separated by newlines).
Deadline August 25, 2014, 1:00 AM EST
As each program WILL be different, no examples are given. I do expect that you understand it enough to give a decent solution.
If any further clarification is needed, contact me. I will try to reduce your sighs (size). (Bad pun, I know )
Problem You must make a game of Snake (or Nibbles, if you know it as that). It must follow all of these guidelines:
It must be played on an square "grid" (each space being the width of one snake segment) as large as possible
The graphics for the food and the snake segments must each be different
The border must be clearly defined, and have different graphics from the food or the snake
The food must spawn on a random EMPTY square, Adriweb
The snake is moved with interactive input (such as a getKey-like command) if possible; if not supported, you may enter a direction each frame
Your snake must wrap around the sides of the board
At game's end, the program must display however many pieces of food were eaten in some way
Your game, above all, must be playable
Deadline August 18, 2014, 1:00 AM EST
As there is random chance involved, and it is interactive input, no sample input shall be given.
If any further clarification is needed, contact me or Runer112. We will try to guide your heads in the right direction. (Get it? Like, you're guiding the snake's head in a certain dire...ah, just forget it.)
Nspire Lua
Rank
User
Size
Board Size
Date
Code
1
Adriweb
548
23*23
8/16/2014 4:57:21 PM
Spoiler For Spoiler:
a,b=5,2 x,y=0,1 g,h={5},{2}c=0 f=0 m=math.random r=table.remove timer.start(.1)on={charIn=function(n)x=({x=-1,z=1})[n]or 0 y=({r=-1,y=1})[n]or 0 end,paint=function(n)z=n.drawString z(n,f,14*a,9*b)for e=1,#g do z(n,8,14*g[e],9*h[e])end end,timer=function()g[#g+1]=(g[#g]+x)%23 h[#h+1]=(h[#h]+y)%23 for n=1,#g-1 do if g[n]==g[#g]and h[n]==h[#h]then error(c)end end if a==g[#g]and b==h[#h]then repeat a=m(22)b=m(21)for n=1,#g do if a==g[n]and b==h[n]then d=0 break else d=1 end end until d>0 c=c+1 else r(g,1)r(h,1)end platform.window:invalidate()end}
TI-83+ BASIC
Rank
User
Size
Board Size
Date
Code
1
JWinslow23
301
21*21
8/11/2014 9:55:09 AM
Spoiler For Spoiler:
26->K 1.01->B {4Ans->A "300fPart(Ans)-2->u "2-3int(Ans->v ClrDraw AxesOff ZStandard 104->Xmax ~72->Ymin ZInteger Vertical 63 For(A,1,440 Repeat not(sum(⌊A=Ans randInt(1,21)+.01randInt(1,21->C End Repeat sum(Ans=C A->dim(⌊A ⌊A(1 Pt-On(u,v,2 B Pt-Off(u,v,2 C Pt-On(u,v,3 Pt-Off(u,v getKey->L If Ans=34 or 2>abs(Ans-25 Ans->K ⌊A(A->B ⌊A(1)+(K=34)-(K=25)+.01((K=26)-(K=24 Ans+21(not(int(Ans))-(22=int(Ans))+.01(not(fPart(Ans))-(.22=fPart(Ans If L=45 or sum(⌊A=Ans Goto 0 augment({Ans},⌊A->A End augment(Ans,{Ans(A->A End Lbl 0 ClrHome A
TI-84+CSE BASIC
Rank
User
Size
Board Size
Date
Code
1
JWinslow23
336
165*165
8/12/2014 4:02:45 PM
Spoiler For Spoiler:
26->K:1.001->B:{4Ans->A ClrDraw:AxesOff BorderColor 3 BackgroundOff:ZStandard Vertical 2.5,12 For(A,1,600 Repeat not(sum(⌊A=Ans randInt(1,165)+.001randInt(1,165->C End Repeat sum(Ans=C A->dim(⌊A ⌊A(1 Pxl-On(fPart(Ans)E3-1,int(Ans-1),14 Pxl-Off(fPart(B)E3-1,1-int(B-1 Pxl-On(fPart(C)E3-1,1-int(C-1),11 getKey->L If Ans=34 or 2>abs(Ans-25 Ans->K ⌊A(A->B ⌊A(1)+(K=34)-(K=25)+.001((K=26)-(K=24 Ans+165(not(int(Ans))-(166=int(Ans)))+.165(not(fPart(Ans))-(.166=fPart(Ans If L=45 or sum(⌊A=Ans Goto 0 augment({Ans},⌊A->A End augment(Ans,{Ans(A->A End Lbl 0 ClrHome A
Java
Rank
User
Size
Board Size
Date
Code
1
ben_g
1610
(screen_height-20)*(screen_height-20)
8/12/2014 1:16:46 PM
Spoiler For Spoiler:
import java.awt.*;import java.awt.event.*;import java.util.*;import java.util.List;import javax.swing.*;class S{static List<N> s;static int x=20,y=20,d=0,h,i=x,j=y,o=0;static Graphics g;public static void main(String[]a){s=new ArrayList<N>();for(int i=0;i<60;i++)s.add(new N(19,20));final JFrame f = new JFrame();f.setUndecorated(true);h=Toolkit.getDefaultToolkit().getScreenSize().height-20;f.setBounds(0,20,h,h);f.addKeyListener(new KeyListener(){@Override public void keyPressed(KeyEvent k){if(k.getKeyCode()==k.VK_ESCAPE)System.exit(0);if(k.getKeyCode()==k.VK_RIGHT)d=0;if(k.getKeyCode()==k.VK_DOWN)d=1;if(k.getKeyCode()==k.VK_LEFT)d=2;if(k.getKeyCode()==k.VK_UP)d=3;}@Override public void keyReleased(KeyEvent k){}@Override public void keyTyped(KeyEvent k){}});JPanel p=new JPanel();f.setContentPane(p);f.setVisible(true);g=f.getGraphics();while(!c(x,y)){x%=h;y%=h;if(x<0)x=h-1;if(y<0)y=h-1;g.setColor(Color.green);g.fillRect(x,y,1,1);g.setColor(Color.red);g.fillRect(i,j,1,1);g.setColor(Color.white);g.fillRect(s.get(0).x,s.get(0).y,1,1);s.add(new N(x,y));if(i==x&&j==y){o=0;for(int i=0;i<30;i++)s.add(new N(x,y));if(s.size()>=h*h)System.exit(0);}else{s.remove(0);}if(o==0){o=1;f();}long m=System.currentTimeMillis();while(System.currentTimeMillis()-m<20){}if(d==0)x++;if(d==1)y++;if(d==2)x--;if(d==3)y--;}System.out.print(s.size()/10-7);System.exit(0);}static void f(){while(c(i,j)){i=(int)(Math.random()*h);j=(int)(Math.random()*h);}}static boolean c(int x,int y){for(int i=0;i<s.size();i++){if(s.get(i).x==x&&s.get(i).y==y){return true;}}return false;}}class N{int x,y;public N(int v,int w){x=v;y=w;}}
f=[7,7] s=[[4,4]] t=0 z=true d=:r l,r=`stty size`.split l=l.to_i-1 while z do print"\x1b[2J\x1b["+f[1].to_s+";"+f[0].to_s+"H*" s.each{|a|print"\x1b["+a[1].to_s+";"+a[0].to_s+"H#"} print"\x1b["+(l+1).to_s+";1H"+t.to_s `stty raw -echo` c=STDIN.read_nonblock(1)rescue nil `stty -raw echo` case c when'a' d=:l when's' d=:d when'w' d=:u when'd' d=:r end x,y=s[-1] case d when:l x-=1 when:d y+=1 when:u y-=1 when:r x+=1 end x=1 if x>l x=l if x<1 y=1 if y>l y=l if y<1 n=[x,y] if s.index(n)!=nil z=false else s.push(n) if n==f t+=1 while(f=[1+rand(l),1+rand(l)]).index(n)!=nil do end else s.shift end end sleep 0.1 end
Challenge 4 To clear anything up, a tie will result in the earlier solution becoming the winner in the category.
Problem For a given string input consisting of only uppercase letters and numbers, add the ASCII value of each alphabetical character (that's 65-90 for uppercase A-Z) and subtract every number. Display the result, but printed vertically with each digit on a new line.
You CAN end up with a negative number, in which case the first line should have a - sign.
If any further clarification is necessary, contact me or willrandship. We will try to keep your heads from exploding.
TI-83+ BASIC
Rank
User
Size
Date
Code
1
Runer112
139
8/7/2014 11:54:17 PM
Spoiler For Spoiler:
Ans->Str1 DelVar BFor(A,1,length(Str1 inString("876543210ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1 B+Ans-9+64(Ans>9->B End " If B<0 Disp Ans+Ans+Ans+"~ For(A,int(~log(abs(B)+not(B)+.1)),~1 Disp iPart(10fPart(abs(B10^(A End
2
JWinslow23
141
8/4/2014 4:34:15 PM
Spoiler For Spoiler:
DelVar CInput Str1 For(X,1,length(Str1 64+inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,X,1 If Ans=64 ~expr(sub(Str1,X,1 C+Ans->C End " If C<0 Pause Ans+Ans+Ans+"~ For(X,~int(log(abs(C))),0 Pause int(abs(C10^(X abs(C)-Ans10^(~X->C End
n=0 function on.charIn(c)n=tonumber(c)and n-c or n+c:byte()s=""..n for i=0,#s do print(s:sub(i,i))end end
2
Adriweb
107 (function body)
8/10/2014 5:48:57 PM
Spoiler For Spoiler:
function codegolf4(s) n=0;for i=1,#s do t=s:sub(i,i):byte()n=n-(t<58 and t-48 or-t)end;z=""..n;for i=1,#z do print(z:sub(i,i))endend
3
Jens_K
115
8/9/2014 5:46:04 PM
Spoiler For Spoiler:
n=0 for c in clipboard.getText():gmatch"."do n=n+(tonumber(c)and -c or c:byte())..""end print((n:gsub(".","%1\n")))
Golfscript
Rank
User
Size
Date
Code
1
Runer112
22
8/7/2014 11:54:17 PM
Spoiler For Spoiler:
0\{.65<\[.48\-]=+}/`n*
CJam
Rank
User
Size
Date
Code
1
Runer112
22
8/7/2014 11:54:17 PM
Spoiler For Spoiler:
0q{i_'A<{48\}0?-+}/`N*
TI-83+ z80
Rank
User
Size
Date
Code
1
Runer112
59
8/7/2014 11:54:17 PM
Spoiler For Spoiler:
;#SECTION "MAIN", CODE
org userMem - 2 db 0BBh, 6Dh Start: B_CALL _RclAns rst rFINDSYM B_CALL _OP1Set0 ex de, hl ld c, (hl) inc hl ld b, (hl) add hl, bc SumLoop: push hl cp 10 jq nc, Letter B_CALL _SetXXOP2 B_CALL _FPSub jq Continue
Letter: add a, '0' B_CALL _SetXXOP2 rst rFPADD Continue: pop hl ld a, (hl) dec hl sub '0' jq nc, SumLoop B_CALL _FormEReal ld l, OP3 & 0FFh DispLoop: ld a, (hl) or a ret z inc hl push hl B_CALL _PutC B_CALL _NewLine pop hl jq DispLoop
Problem Make a program that, given an integer of reasonable size, outputs the greatest prime factor of that integer, in binary, but with all 0s replaced with underscores (_) and all 1s replaced with minus signs (-).
class C{public static void main(String[]a){long x=Long.decode(a[0]),i=x;while(i-->2)x=(x%i)==0?i:x;System.out.print(Long.toString(x,2).replace('0','_').replace('1','-'));}}
2
3298
185
8/3/2014 6:16:11 PM
Spoiler For Spoiler:
class G{public static void main(String[]c){int n=Integer.parseInt(c[0]),i=2;while(i<n)if(n%i==0)n/=i;else++i;System.out.print(Integer.toString(n,2).replace('0','_').replace('1','-'));}}
TI-83+ z80
Rank
User
Size
Date
Code
1
Runer112
58
8/3/2014 2:17:19 PM
Spoiler For Spoiler:
;#SECTION "MAIN", CODE
org userMem - 2 db 0BBh, 6Dh Start: B_CALL _RclAns B_CALL _ConvOP1 ld h, d ld l, e TrialDivideLoop: push de push hl B_CALL _DivHLByDE ld a, h or l pop hl pop de jq nz, NotFactor ld h, d ld l, e NotFactor: dec de ld a, e dec a or d jq nz, TrialDivideLoop ld b, h ld c, l ld hl, OP1 + 15 ld (hl), d BitLoop: dec hl srl b rr c ld (hl), '_' jq nc, BitUnset ld (hl), '-' ld d, h ld e, l BitUnset: jq nz, BitLoop ex de, hl B_CALL _PutS B_CALL _NewLine ret
XTend
Rank
User
Size
Date
Code
1
3298
179
8/3/2014 6:16:11 PM
Spoiler For Spoiler:
class G{def static void main(String[]c){var n=Integer.parseInt(c.get(0))var i=2while(i<n)if(n%i==0)n=n/i else i=i+1print(Integer.toString(n,2).replace('0','_').replace('1','-'))}}
Language Ranking
Rank
Lang
User
Size
Date
1
CJam
Runer112
16
8/3/2014 2:17:19 PM
2
Golfscript
Runer112
33
8/3/2014 2:17:19 PM
3
TI-83+ z80
Runer112
58
8/3/2014 2:17:19 PM
4
SysRPL
3298
59.5 (don't ask me why; I'm going off of what he said)
s,n="",0 for w in clipboard.getText():gmatch"%S+"do if tonumber(w)then n=n+w else s=w.." "..s end end print(s..n)
2
LDStudios
162
7/23/2014 3:30:25 PM
Spoiler For Spoiler:
i="" p={} function on.charIn(h) s="" i=i..h p=i:split(s) n=0 for i,v in ipairs(p) do if v:find("%a") then s=v.." "..s elseif v:find("%d") then n=n+v end end print(i) print(s..n) end
Python3
Rank
User
Size
Date
Code
1
willrandship
83
7/22/2014 3:08:29 PM
Spoiler For Spoiler:
s=0;o='' for w in input().split(): try:s+=int(w) except:o=o+w+" " print(o+str(s))
Java
Rank
User
Size
Date
Code
1
Runer112
174
7/27/2014 12:27:24 PM
Spoiler For Spoiler:
class B{public static void main(String[]a){int x=0,i=a.length;while(i>0)try{x+=Integer.parseInt(a[--i]);}catch(Exception e){System.out.print(a+' ');}System.out.print(x);}}
public class Main{public static void main(String[] args){String s="";int i=0;for(String t:args[0].split(" ")){try{i+=Integer.parseInt(t);}catch(Exception e){s=t+" "+s;}}s+=i;System.out.println(s);}}
CJam
Rank
User
Size
Date
Code
1
Runer112
27
7/27/2014 12:27:24 PM
Spoiler For Spoiler:
qS%W%0\{_:i:|'A<{~+}{S@}?}/
XTend
Rank
User
Size
Date
Code
1
3298
159
7/27/2014 1:58:00 PM
Spoiler For Spoiler:
class G{static var n=0;def static void main(String[]c){println(c.get(0).split(" ").fold("")[s,i|try{n=n+Integer.parseInt(i);s}catch(Exception _){i+" "+s}]+n)}}
Haskell
Rank
User
Size
Date
Code
1
3298
138
7/27/2014 1:58:00 PM
Spoiler For Spoiler:
import Text.Read g c=(fst f)++show(snd f)where f=foldr(\i(s,n)->case readMaybe i of Nothing->(s++i++" ",n);Just m->(s,n+m))("",0)(words c)
This is the first of what I hope to be many contests I will hold here on Omnimaga: Code Golf.
Code golf is a competition where you have to solve a coding challenge in the fewest bytes possible. For example, a TI-BASIC entry for a prime tester could be:
Input N:0:If N and not(fPart(N:2=sum(seq(not(fPart(abs(N)/I)),I,1,abs(N:Ans(note that this is not the speediest it could be, but speed is not factored in your score, only size) The score would be 34 bytes (for TI-BASIC programs, score=size - 9 - length of name). The lowest score out of the entries will be the winner.
How this tournament will work: First off, you need to code an actual program that will solve the given problem (or at least give the right result for all the test cases ). All languages are allowed, including calc languages and computer languages. When you have an entry, PM it to me, and I will test it if possible (but just in case I don't have an Nspire or I can't download the latest version of Perl or some such problem, try if you can to give back the results of any and all given test cases). I will then save your entry and update the scores accordingly. After one week, a winner shall be determined in each language category, as well as the smallest overall. In each language category, the winners shall all suggest possible problems for the next competition. I shall pick the next challenge out of these, and present test cases for any possible input or output. Also, you will get to see everyone else's solutions for the previous challenge.
Please, ask any and all questions that you may have about the contest!
Problem Determine if an inputted number is happy. Happy numbers are defined like this: Take any positive integer, replace it with the sum of the squares of its digits, and repeat the process until it equals 1 or it loops indefinitely in a loop that does not include 1. If it ends up with 1, the number is happy, otherwise it's sad. Deadline July 21, 2014, 1:00 AM EST Sample input 1: 1 Sample output 1:
x=input();b="UNHAPPY" for a in b: z=0 for y in str(x):z+=eval(y)**2;x=z print(b[(z==1)*2:7])
2
Juju
148
7/15/2014 4:22:50 PM
Spoiler For Spoiler:
def h(n): while n>1 and n!=4: n=sum(dict([(c,int(c)**2)for c in"0123456789"])[d] for d in str(n)) return n==1 print(("SAD","HAPPY")[h(input())])
Golfscript
Rank
User
Size
Date
Code
1
Runer112
32
7/15/2014 5:17:50 PM
Spoiler For Spoiler:
~{`0\{48-.*+}/}9*("SAD""HAPPY"if
CJam
Rank
User
Size
Date
Code
1
Runer112
30
7/15/2014 5:17:50 PM
Spoiler For Spoiler:
q~{Ab0\{_*+}/}9*("SAD""HAPPY"?
TI-83+ BASIC
Rank
User
Size
Date
Code
1
calc84maniac
46
7/16/2014 5:03:49 PM
Spoiler For Spoiler:
Repeat Ans<5 sum(.5×√int(10fPart(Ans/10^(cumSum(binomcdf(98,0→A End "HAPPY If log(A "SAD Ans
2
Runer112
46
7/16/2014 5:09:28 PM
Spoiler For Spoiler:
Repeat A≤4 iPart(10fPart(Ans10^(~cumSum(binomcdf(14,0 sum(Ans²→A End "HAPPY If log(A "SAD Ans
3
Hayleia
71
7/16/2014 2:18:36 AM
Spoiler For Spoiler:
Prompt N Repeat N=1 or N=4 sum(seq((10fPart(iPart(N10^(~I))/10))²,I,0,14→N End "HAPPY If N=4 "SAD Disp Ans
TI-83+ z80
Rank
User
Size
Date
Code
1
Runer112
58
7/20/2014 9:32:08 PM
Spoiler For Spoiler:
;#SECTION "MAIN", CODE
org userMem - 2 db 0BBh, 6Dh Start: B_CALL _RclAns StepLoop: push bc sbc hl, hl ld b, h DigitPairLoop: dec e DigitLoop: ex de, hl xor a rrd ex de, hl ld c, a SquareLoop: add hl, bc dec a jq nz, SquareLoop ld a, (de) or a jq nz, DigitLoop ld a, e cp (OP1 + 2) & 0FFh jq nz, DigitPairLoop push hl B_CALL _SetXXXXOP2 rst 30h pop hl pop bc djnz StepLoop dec l ld hl, UnhappyStr jq nz, Unhappy inc hl inc hl Unhappy: B_CALL _PutS ret
.org $9D93 .db $BB,$6D bcall(_RclAns) ex de,hl HappyCalcLoop: xor a ld c,a ld d,a ld e,a HappyByteLoop: ;Carry is reset, upper nibble of A is 0 dec l HappyNibbleLoop: rrd ld b,a HappyMulLoop: push af add a,e daa ld e,a ld a,c adc a,d daa ld d,a pop af djnz HappyMulLoop ccf jr c,HappyNibbleLoop ld a,l sub (OP1+2)&$FF jr nz,HappyByteLoop ld (hl),d inc l ld (hl),e inc l inc (hl) jr nz,HappyCalcLoop ld hl,HappyString dec e jr z,$+4 dec hl dec hl bcall(_PutS) ret
I would like to propose a monthly contest on Omnimaga: Code Golf.
Code golf is basically solving a certain coding problem in the fewest amount of bytes possible. For example, a golfed primality tester in TI-BASIC would be:
Input N:0:If N and not(fPart(N:2=sum(seq(not(fPart(abs(N)/I)),I,1,abs(N:AnsThe score then would be 43 bytes (technically, 43+length of name, but for calc-language purposes, the name is not included in the score). Lowest score wins. (note this isn't as speedy as it could be, but speed would not count against you) If possible, have it work for as many possible test cases as you can while still making it short.
Anybody could submit challenges (so long as you give test cases as well). Hopefully we can allow all calc languages, as well as computer languages (so long as you can test them, and you can show us the results of the test cases).
Who would I talk to in order to get something like this started here?
This is a collection of phrases that describe the number of letters that the phrase has. For example, "a two written next to a one" describes 21, and has 21 letters. Here are some examples from 1 to 100:
I have worked for months on this game, and it is FINALLY ready for a release! Click the gif image to jump to the latest version!
TI-2048 Join the numbers and get to the 2048 tile! HOW TO PLAY: Use your arrow keys to move the tiles. When two tiles with the same number touch, they merge into one!
NOTE: This is not the official version of 2048; it is simply a port. You can play the original at http://git.io/2048. All other apps or sites are derivatives or fakes, and should be used with caution.
Please help me with optimizations and play testing, everyone! Give me any suggestions you can! Seriously, my code is kinda hackish right now.
NOTE: This requires A2048 and LIB3BYTE on your calc to compile properly. I'll compress it soon, I promise. This also saves your highscore in an appvar called "TI2048". It is automatically archived upon exit.
Spoiler For Credits:
Hayleia for providing tile graphics, and moral support. Runer112 for general support, a library giving me access to 3-byte numbers, and giving me the sliding algorithm that eluded me for SO long! I know I told you this before with another project, but this would only have been an idea without you! willrandship for...something I forget. Optimization? I swear, this project is really taking a toll on my memory. The whole Omnimaga community for giving me support along the way!