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

0 Members and 1 Guest are viewing this topic.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
[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.

Deadline
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
RankUserSizeDateCode
1Runer1121398/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
2JWinslow231418/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

Ruby2
RankUserSizeDateCode
1Juju988/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}

Haskell
RankUserSizeDateCode
1bb010g688/8/2014 12:54:03 PM
Spoiler For Spoiler:
mapM(putStrLn.(:[])).show.sum.map((\x->x+(48-2*x)*div 57x).fromEnum)
23298708/7/2014 6:55:04 AM
Spoiler For Spoiler:
g s=mapM(putStrLn.(:[]))$show$sum$map(n.fromEnum)s
n c|c<58=48-c|c>0=c

SysRPL
RankUserSizeDateCode
1329863.58/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
RankUserSizeDateCode
1Runer112137 (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"));}}
232981568/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
RankUserSizeDateCode
132981258/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
RankUserSizeDateCode
1willrandship688/5/2014 7:50:40 PM
Spoiler For Spoiler:
for(split//,<>){$b+=ord($_)>64?ord($_):-$_;}$b=~s/(.)/$1\n/g;print$b

NSpire Lua
RankUserSizeDateCode
1LDStudios1058/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=""..n
for i=0,#s do print(s:sub(i,i))end end
2Adriweb107 (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
3Jens_K1158/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
RankUserSizeDateCode
1Runer112228/7/2014 11:54:17 PM
Spoiler For Spoiler:
0\{.65<\[.48\-]=+}/`n*

CJam
RankUserSizeDateCode
1Runer112228/7/2014 11:54:17 PM
Spoiler For Spoiler:
0q{i_'A<{48\}0?-+}/`N*

TI-83+ z80
RankUserSizeDateCode
1Runer112598/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

C
RankUserSizeDateCode
132981548/9/2014 5:14:18 AM
Spoiler For Spoiler:
#include <stdio.h>
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

RankLangUserSizeDate
1CJamRuner112228/7/2014 11:54:17 PM
2GolfscriptRuner112228/7/2014 11:54:17 PM
3TI-83+ z80Runer112598/7/2014 11:54:17 PM
4SysRPL329863.58/7/2014 9:07:43 AM
5Perlwillrandship688/5/2014 7:50:40 PM
6Haskellbb010g688/8/2014 12:54:03 PM
7Ruby2Juju988/4/2014 8:02:43 PM
8NSpire LuaLDStudios1058/10/2014 1:27:16 PM
9XTend32981258/9/2014 5:14:28 AM
10JavaRuner112137 (requires Java 8 ) 8/10/2014 12:43:30 PM
11TI-83+ BASICRuner1121398/7/2014 11:54:17 PM
12C32981548/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"?
Click here for the only set of games you'll ever need
= ?

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
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?
THEGAME
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.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
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

Offline bb010g

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 428
  • Rating: +22/-1
  • I do stuff
    • View Profile
    • elsewhere on the net
Re: Code Golf Contest #4
« Reply #3 on: August 04, 2014, 07:24:05 pm »
85 bytes of Haskell. ;D
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

Offline 3298

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

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
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... :mad:

But yeah, interesting solutions so far!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline bb010g

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 428
  • Rating: +22/-1
  • I do stuff
    • View Profile
    • elsewhere on the net
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

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
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. :P I'll get right on that.

EDIT: Added NEXT/PREVIOUS buttons.
« Last Edit: August 04, 2014, 08:32:12 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline willrandship

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

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
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"?
Click here for the only set of games you'll ever need
= ?

Offline bb010g

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 428
  • Rating: +22/-1
  • I do stuff
    • View Profile
    • elsewhere on the net
Re: Code Golf Contest #4
« Reply #10 on: August 06, 2014, 07:26:56 pm »
\o/ 77 bytes in Haskell!
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

Offline 3298

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +1/-0
    • View Profile
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 :crazy: ... 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 »

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
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 :crazy: ... 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. :P

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"?
Click here for the only set of games you'll ever need
= ?

Offline LDStudios

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



Offline bb010g

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 428
  • Rating: +22/-1
  • I do stuff
    • View Profile
    • elsewhere on the net
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 :crazy: ... 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