Calculator Community > Community Contests

[ENDED] Code Golf Contest #2

(1/6) > >>

JWinslow23:
Here is the second code golf contest. Rules here.

NEXT: Here
PREVIOUS: Here

Challenge 2

Problem
Make a program with the following input and output:

Input: A string of any length, made up of clusters of characters and numbers separated by spaces.

Output: All non-number "words", concatenated together in reverse order, with the sum of all numeric "words" following, all separated by spaces.

Deadline
July 28, 2014, 1:00 AM EST

Sample input 1
"1 asdf 15 1fg Iamamazing 14"
Sample output 1
"Iamamazing 1fg asdf 30"
Sample input 2
"Hello W0rld 63 How 4r3 you 6"
Sample output 2
"you 4r3 How W0rld Hello 69"

If any further clarification is necessary, please contact me or willrandship. We will try to explain.

Ranking

Ruby 2
RankUserSizeDateCode1Juju807/23/2014 12:39:40 PMSpoiler For Spoiler: a=0;print gets.split.reverse.reject{|b|a!=a+=Integer(b)rescue 0}.join(" ")," ",a
Golfscript
RankUserSizeDateCode1Runer112327/27/2014 12:27:24 PMSpoiler For Spoiler: " "%-1%0\{.{|}*64<{~+}{" "@}if}/2JWinslow23607/22/2014 1:02:09 PMSpoiler For Spoiler: " "%-1%0:a;{..{.47>\59<and},={~a+:a;}{}if}/]{.!{}{" "+}if}/a
Nspire Lua
RankUserSizeDateCode1Jens_K113 (copy input to clipboard)7/23/2014 9:15:32 AMSpoiler For Spoiler: 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)2LDStudios1627/23/2014 3:30:25 PMSpoiler 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
RankUserSizeDateCode1willrandship837/22/2014 3:08:29 PMSpoiler For Spoiler: s=0;o=''
for w in input().split():
 try:s+=int(w)
 except:o=o+w+" "
print(o+str(s))
Java
RankUserSizeDateCode1Runer1121747/27/2014 12:27:24 PMSpoiler 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);}}232981787/27/2014 1:58:00 PMSpoiler For Spoiler: class G{public static void main(String[]c){int n=0;String s="";for(String i:c[0].split(" ")){try{n+=Integer.parseInt(i);}catch(Exception e){s=i+" "+s;}}System.out.println(s+n);}}3ben_g1987/22/2014 4:01:06 PMSpoiler For Spoiler: 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
RankUserSizeDateCode1Runer112277/27/2014 12:27:24 PMSpoiler For Spoiler: qS%W%0\{_:i:|'A<{~+}{S@}?}/
XTend
RankUserSizeDateCode132981597/27/2014 1:58:00 PMSpoiler 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
RankUserSizeDateCode132981387/27/2014 1:58:00 PMSpoiler 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)
SysRPL
RankUserSizeDateCode13298797/27/2014 1:58:00 PMSpoiler For Spoiler: ::
  BINT0 FPTR2 ^StrCutNchr_
  Z0_ NULL$ ROT BEGIN
    SEP$NL FPTR2 ^S>Z? ITE
    :: 4ROLL FPTR2 ^QAdd UNROT ;
    :: APPEND_SPACE ROT &$SWAP ;
  DUPNULL$? UNTIL
  DROPSWAP FPTR2 ^Z>S &$
;
Language Ranking

RankLangUserSizeDate1CJamRuner112277/27/2014 12:27:24 PM2GolfscriptRuner112327/27/2014 12:27:24 PM3SysRPL3298797/27/2014 1:58:00 PM4Ruby 2Juju807/23/2014 12:39:40 PM5Python3willrandship837/22/2014 3:08:29 PM6Nspire LuaJens_K113 (copy input to clipboard)7/23/2014 9:15:32 AM7Haskell32981387/27/2014 1:58:00 PM8XTend32981597/27/2014 1:58:00 PM9JavaRuner1121747/27/2014 1:58:00 PM

Juju:
Woo, got 99 bytes in Ruby.

JWinslow23:
Yup. And I finally figured out a Golfscript solution.

willrandship:
Here's a handy tool to get your code size.

http://mothereff.in/byte-counter

Juju:
Aha, down to 80 bytes! Try to beat me :P

Navigation

[0] Message Index

[#] Next page

Go to full version