### Author Topic: [ENDED] Code Golf Contest #4  (Read 17517 times)

0 Members and 1 Guest are viewing this topic.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### [ENDED] Code Golf Contest #4
« on: August 04, 2014, 05:37:33 pm »
You know the drill.

NEXT: Here
PREVIOUS: Here

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.

August 11, 2014, 1:00 AM EST

Sample input 1
A45FTUX
Sample output 1
3
8
3
Sample input 2
99A874512995
Sample output 2
-
3
Sample input 3
CODEGOLF
Sample output 3
5
7
9

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->Str1DelVar BFor(A,1,length(Str1inString("876543210ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1B+Ans-9+64(Ans>9->BEnd"     If B<0Disp Ans+Ans+Ans+"~For(A,int(~log(abs(B)+not(B)+.1)),~1Disp iPart(10fPart(abs(B10^(AEnd 2 JWinslow23 141 8/4/2014 4:34:15 PM Spoiler For Spoiler: DelVar CInput Str1For(X,1,length(Str164+inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,X,1If Ans=64~expr(sub(Str1,X,1C+Ans->CEnd"     If C<0Pause Ans+Ans+Ans+"~For(X,~int(log(abs(C))),0Pause int(abs(C10^(Xabs(C)-Ans10^(~X->CEnd

Ruby2
 Rank User Size Date Code 1 Juju 98 8/4/2014 8:02:43 PM Spoiler For Spoiler: a=0;gets.chomp.each_char{|b|c=('0'..'9')===b&&1||-1;a-=c*b.ord-(24*c+24)};a.to_s.each_char{|b|p b}

 Rank User Size Date Code 1 bb010g 68 8/8/2014 12:54:03 PM Spoiler For Spoiler: mapM(putStrLn.(:[])).show.sum.map((\x->x+(48-2*x)*div 57x).fromEnum) 2 3298 70 8/7/2014 6:55:04 AM Spoiler For Spoiler: g s=mapM(putStrLn.(:[]))$show$sum$map(n.fromEnum)sn c|c<58=48-c|c>0=c SysRPL  Rank User Size Date Code 1 3298 63.5 8/7/2014 9:07:43 AM Spoiler For Spoiler: :: %0 OVERLEN$ #1+_ONE_DO    OVERINDEX@ SUB$1# BINT58 OVER#> IT :: UNCOERCE %- BINT48 ; UNCOERCE %+ LOOP xR>I DO>STR ONE MINUSONE FPTR2 ^StrCutNchr2_ DROPSWAPDROP; Java  Rank User Size Date Code 1 Runer112 137 (requires Java 8 ) 8/10/2014 12:43:30 PM Spoiler For Spoiler: class D{public static void main(String[]a){System.out.print(Long.toString(a[0].chars().map(c->c<65?48-c:c).sum()).replaceAll("","\n"));}} 2 3298 156 8/9/2014 5:14:28 AM Spoiler For Spoiler: class G{public static void main(String[]c){Long n=0L;for(int p:c[0].getBytes())n+=p<58?48-p:p;for(char p:n.toString().toCharArray())System.out.println(p);}} XTend  Rank User Size Date Code 1 3298 125 8/9/2014 5:14:28 AM Spoiler For Spoiler: class G{def static main(String[]c){for(p:c.head.getBytes.fold(0)[n,p|n+if(p<58)48-p else p].toString.toCharArray)println(p)}} Perl  Rank User Size Date Code 1 willrandship 68 8/5/2014 7:50:40 PM Spoiler For Spoiler: for(split//,<>){$b+=ord($_)>64?ord($_):-$_;}$b=~s/(.)/$1\n/g;print$b

NSpire Lua
 Rank User Size Date Code 1 LDStudios 105 8/10/2014 1:27:16 PM Spoiler For Spoiler: n=0 function on.charIn(c)n=tonumber(c)and n-c or n+c:byte()s=""..nfor 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=0for c in clipboard.getText():gmatch"."don=n+(tonumber(c)and -c or c:byte())..""endprint((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, 6DhStart:   B_CALL   _RclAns   rst   rFINDSYM   B_CALL   _OP1Set0   ex   de, hl   ld   c, (hl)   inc   hl   ld   b, (hl)   add   hl, bcSumLoop:   push   hl   cp   10   jq   nc, Letter   B_CALL   _SetXXOP2   B_CALL   _FPSub   jq   ContinueLetter:   add   a, '0'   B_CALL   _SetXXOP2   rst   rFPADDContinue:   pop   hl   ld   a, (hl)   dec   hl   sub   '0'   jq   nc, SumLoop   B_CALL   _FormEReal   ld   l, OP3 & 0FFhDispLoop:   ld   a, (hl)   or   a   ret   z   inc   hl   push   hl   B_CALL   _PutC   B_CALL   _NewLine   pop   hl   jq   DispLoop

C
 Rank User Size Date Code 1 3298 154 8/9/2014 5:14:18 AM Spoiler For Spoiler: #include main(int x,char**c){char s[12],*p=c[1];int n=0;for(;*p>0;++p){n+=*p<58?48-*p:*p;}sprintf(s,"%i",n);for(p=s;*p>0;++p)printf("%c\n",*p);}

Language Ranking

 Rank Lang User Size Date 1 CJam Runer112 22 8/7/2014 11:54:17 PM 2 Golfscript Runer112 22 8/7/2014 11:54:17 PM 3 TI-83+ z80 Runer112 59 8/7/2014 11:54:17 PM 4 SysRPL 3298 63.5 8/7/2014 9:07:43 AM 5 Perl willrandship 68 8/5/2014 7:50:40 PM 6 Haskell bb010g 68 8/8/2014 12:54:03 PM 7 Ruby2 Juju 98 8/4/2014 8:02:43 PM 8 NSpire Lua LDStudios 105 8/10/2014 1:27:16 PM 9 XTend 3298 125 8/9/2014 5:14:28 AM 10 Java Runer112 137 (requires Java 8 ) 8/10/2014 12:43:30 PM 11 TI-83+ BASIC Runer112 139 8/7/2014 11:54:17 PM 12 C 3298 154 8/9/2014 5:14:18 AM
« Last Edit: June 11, 2015, 08:58:12 am by pimathbrainiac »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### Juju

• Incredibly sexy mare
• Coder Of Tomorrow
• LV13 Extreme Addict (Next: 9001)
• Posts: 5730
• Rating: +500/-19
• Weird programmer
##### Re: Code Golf Contest #4
« Reply #1 on: August 04, 2014, 06:04:23 pm »
104 bytes of Ruby! And it's not even been 30 minutes this topic has been posted!

Edit: Yet another 98-byte entry o.o
« Last Edit: August 04, 2014, 06:42:24 pm by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?

This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
##### Re: Code Golf Contest #4
« Reply #2 on: August 04, 2014, 06:36:09 pm »
I currently have 202 bytes in java, and I'm already pretty much stuck at optimizing it.
« Last Edit: August 04, 2014, 06:47:05 pm by ben_g »
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### bb010g

• LV6 Super Member (Next: 500)
• Posts: 428
• Rating: +22/-1
• I do stuff
##### Re: Code Golf Contest #4
« Reply #3 on: August 04, 2014, 07:24:05 pm »
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE

#### 3298

• LV2 Member (Next: 40)
• Posts: 26
• Rating: +1/-0
##### Re: Code Golf Contest #4
« Reply #4 on: August 04, 2014, 07:39:02 pm »
69.5 bytes in SysRPL. I'll try Java, XTend and Haskell soon, as usual.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #4
« Reply #5 on: August 04, 2014, 08:21:16 pm »
Already, every entry has beaten my TI-BASIC entry...the last contest, that didn't happen until SysRPL...

But yeah, interesting solutions so far!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### bb010g

• LV6 Super Member (Next: 500)
• Posts: 428
• Rating: +22/-1
• I do stuff
##### Re: Code Golf Contest #4
« Reply #6 on: August 04, 2014, 08:22:23 pm »
You should stick Next/Previous links in each of these Contest posts.
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #4
« Reply #7 on: August 04, 2014, 08:26:59 pm »
You should stick Next/Previous links in each of these Contest posts.
Well, I thought it would all derail by the end of Contest #2. I'll get right on that.

« Last Edit: August 04, 2014, 08:32:12 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### willrandship

• Omnimagus of the Multi-Base.
• LV11 Super Veteran (Next: 3000)
• Posts: 2953
• Rating: +98/-13
• Insert sugar to begin programming subroutine.
##### Re: Code Golf Contest #4
« Reply #8 on: August 05, 2014, 07:58:22 pm »
75 bytes of perl submitted

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #4
« Reply #9 on: August 06, 2014, 04:56:59 pm »
Woo! Now we have a new record to beat! 68 bytes, anyone?
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### bb010g

• LV6 Super Member (Next: 500)
• Posts: 428
• Rating: +22/-1
• I do stuff
##### Re: Code Golf Contest #4
« Reply #10 on: August 06, 2014, 07:26:56 pm »
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE

#### 3298

• LV2 Member (Next: 40)
• Posts: 26
• Rating: +1/-0
##### Re: Code Golf Contest #4
« Reply #11 on: August 07, 2014, 07:55:28 am »
How the heck did you compress the Haskell code like that ... nevermind, got 71 bytes now, assuming Unix-style line endings (with DOS-style 2-byte line endings it's 72). Take that!
Edit: Also cut down the SysRPL program size to 63.5. I don't expect to be able to compete with CJam and Golfscript, but at least SysRPL is useful for real problems.
By the way, the compactness of that language comes from the fact that programs are usually stored in compiled form. Judging from the prime tester example in the post from the first round, TI-Basic does something similar, though (it seems commands take 1 byte each, instead of 1 byte per character in their names), so I don't feel bad for telling you the compiled size instead of the much larger source size. I know Casio-Basic does those 1-byte commands as well, but because string manipulation is not present in the Casio-Basic version on my calcs, I cannot submit a Casio-Basic entry. (String manipulation was introduced in OS 2.00 for the 9860 series.)
« Last Edit: August 07, 2014, 10:20:34 am by 3298 »

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #4
« Reply #12 on: August 07, 2014, 01:49:51 pm »
How the heck did you compress the Haskell code like that ... nevermind, got 71 bytes now, assuming Unix-style line endings (with DOS-style 2-byte line endings it's 72). Take that!
Edit: Also cut down the SysRPL program size to 63.5. I don't expect to be able to compete with CJam and Golfscript, but at least SysRPL is useful for real problems.
By the way, the compactness of that language comes from the fact that programs are usually stored in compiled form. Judging from the prime tester example in the post from the first round, TI-Basic does something similar, though (it seems commands take 1 byte each, instead of 1 byte per character in their names), so I don't feel bad for telling you the compiled size instead of the much larger source size. I know Casio-Basic does those 1-byte commands as well, but because string manipulation is not present in the Casio-Basic version on my calcs, I cannot submit a Casio-Basic entry. (String manipulation was introduced in OS 2.00 for the 9860 series.)
Actually, there are 2-byte tokens in TI-BASIC, and lots of them. That is part of the reason why we don't like lowercase letters.

Looks like things are getting pretty heated in the Haskell category! 3298 and bb010g are slashing bytes like crazy! Only thing to wonder now is, when will they stop? (And will it be before the competition's over?)
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### LDStudios

• Coder Of Tomorrow
• LV6 Super Member (Next: 500)
• Posts: 388
• Rating: +41/-1
##### Re: Code Golf Contest #4
« Reply #13 on: August 07, 2014, 03:22:30 pm »
122 bytes in nspire lua

#### bb010g

• LV6 Super Member (Next: 500)
• Posts: 428
• Rating: +22/-1
• I do stuff
##### Re: Code Golf Contest #4
« Reply #14 on: August 07, 2014, 04:22:50 pm »
How the heck did you compress the Haskell code like that ... nevermind, got 71 bytes now, assuming Unix-style line endings (with DOS-style 2-byte line endings it's 72). Take that!
Edit: Also cut down the SysRPL program size to 63.5. I don't expect to be able to compete with CJam and Golfscript, but at least SysRPL is useful for real problems.
DAAAAAAAAAANG.
* bb010g opens up GHCi again
Arch Linux user
Haskell newbie | Warming up to Lua | Being dragged into C++
Calculators: HP 50g, HP 35s, Casio Prizm, TI-Nspire CX CAS, HP 28s, HP Prime, Mathematica 9 (if that counts)
π: 3.14...; l: 108; i: 105; e: 101; l+i+e: 314
THE CAKE IS A LIE IS A PIE