Calculator Community > Community Contests

[ENDED] Code Golf Contest #4

(1/11) > >>

JWinslow23:
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
RankUserSizeDateCode1Runer1121398/7/2014 11:54:17 PMSpoiler 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
End2JWinslow231418/4/2014 4:34:15 PMSpoiler 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
RankUserSizeDateCode1Juju988/4/2014 8:02:43 PMSpoiler 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
RankUserSizeDateCode1bb010g688/8/2014 12:54:03 PMSpoiler For Spoiler: mapM(putStrLn.(:[])).show.sum.map((\x->x+(48-2*x)*div 57x).fromEnum)23298708/7/2014 6:55:04 AMSpoiler For Spoiler: g s=mapM(putStrLn.(:[]))$show$sum$map(n.fromEnum)s
n c|c<58=48-c|c>0=c
SysRPL
RankUserSizeDateCode1329863.58/7/2014 9:07:43 AMSpoiler 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
RankUserSizeDateCode1Runer112137 (requires Java 8 ) 8/10/2014 12:43:30 PMSpoiler 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 AMSpoiler 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
RankUserSizeDateCode132981258/9/2014 5:14:28 AMSpoiler 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
RankUserSizeDateCode1willrandship688/5/2014 7:50:40 PMSpoiler For Spoiler: for(split//,<>){$b+=ord($_)>64?ord($_):-$_;}$b=~s/(.)/$1\n/g;print$b
NSpire Lua
RankUserSizeDateCode1LDStudios1058/10/2014 1:27:16 PMSpoiler 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 end2Adriweb107 (function body)8/10/2014 5:48:57 PMSpoiler 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))endend3Jens_K1158/9/2014 5:46:04 PMSpoiler 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
RankUserSizeDateCode1Runer112228/7/2014 11:54:17 PMSpoiler For Spoiler: 0\{.65<\[.48\-]=+}/`n*
CJam
RankUserSizeDateCode1Runer112228/7/2014 11:54:17 PMSpoiler For Spoiler: 0q{i_'A<{48\}0?-+}/`N*
TI-83+ z80
RankUserSizeDateCode1Runer112598/7/2014 11:54:17 PMSpoiler 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
RankUserSizeDateCode132981548/9/2014 5:14:18 AMSpoiler 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

RankLangUserSizeDate1CJamRuner112228/7/2014 11:54:17 PM2GolfscriptRuner112228/7/2014 11:54:17 PM3TI-83+ z80Runer112598/7/2014 11:54:17 PM4SysRPL329863.58/7/2014 9:07:43 AM5Perlwillrandship688/5/2014 7:50:40 PM6Haskellbb010g688/8/2014 12:54:03 PM7Ruby2Juju988/4/2014 8:02:43 PM8NSpire LuaLDStudios1058/10/2014 1:27:16 PM9XTend32981258/9/2014 5:14:28 AM10JavaRuner112137 (requires Java 8 ) 8/10/2014 12:43:30 PM11TI-83+ BASICRuner1121398/7/2014 11:54:17 PM12C32981548/9/2014 5:14:18 AM

Juju:
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

ben_g:
I currently have 202 bytes in java, and I'm already pretty much stuck at optimizing it.

bb010g:
85 bytes of Haskell. ;D

3298:
69.5 bytes in SysRPL. :blah: I'll try Java, XTend and Haskell soon, as usual.

Navigation

[0] Message Index

[#] Next page

Go to full version