Author Topic: [ENDED] Code Golf Contest #2  (Read 4987 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 #2
« on: July 22, 2014, 11:32:51 am »
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
RankUserSizeDateCode
1Juju807/23/2014 12:39:40 PM
Spoiler For Spoiler:
a=0;print gets.split.reverse.reject{|b|a!=a+=Integer(b)rescue 0}.join(" ")," ",a

Golfscript
RankUserSizeDateCode
1Runer112327/27/2014 12:27:24 PM
Spoiler For Spoiler:
" "%-1%0\{.{|}*64<{~+}{" "@}if}/
2JWinslow23607/22/2014 1:02:09 PM
Spoiler For Spoiler:
" "%-1%0:a;{..{.47>\59<and},={~a+:a;}{}if}/]{.!{}{" "+}if}/a

Nspire Lua
RankUserSizeDateCode
1Jens_K113 (copy input to clipboard)7/23/2014 9:15:32 AM
Spoiler 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 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
RankUserSizeDateCode
1willrandship837/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
RankUserSizeDateCode
1Runer1121747/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);}}
232981787/27/2014 1:58:00 PM
Spoiler 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 PM
Spoiler 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
RankUserSizeDateCode
1Runer112277/27/2014 12:27:24 PM
Spoiler For Spoiler:
qS%W%0\{_:i:|'A<{~+}{[email protected]}?}/

XTend
RankUserSizeDateCode
132981597/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
RankUserSizeDateCode
132981387/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)

SysRPL
RankUserSizeDateCode
13298797/27/2014 1:58:00 PM
Spoiler 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

RankLangUserSizeDate
1CJamRuner112277/27/2014 12:27:24 PM
2GolfscriptRuner112327/27/2014 12:27:24 PM
3SysRPL3298797/27/2014 1:58:00 PM
4Ruby 2Juju807/23/2014 12:39:40 PM
5Python3willrandship837/22/2014 3:08:29 PM
6Nspire LuaJens_K113 (copy input to clipboard)7/23/2014 9:15:32 AM
7Haskell32981387/27/2014 1:58:00 PM
8XTend32981597/27/2014 1:58:00 PM
9JavaRuner1121747/27/2014 1:58:00 PM
« Last Edit: June 11, 2015, 08:58:45 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 #2
« Reply #1 on: July 22, 2014, 12:42:06 pm »
Woo, got 99 bytes in Ruby.

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 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 #2
« Reply #2 on: July 22, 2014, 03:07:16 pm »
Yup. And I finally figured out a Golfscript solution.
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 #2
« Reply #3 on: July 22, 2014, 04:56:51 pm »
Here's a handy tool to get your code size.

http://mothereff.in/byte-counter

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 #2
« Reply #4 on: July 23, 2014, 02:08:51 am »
Aha, down to 80 bytes! Try to beat me :P

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 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 #2
« Reply #5 on: July 23, 2014, 03:28:19 am »
Aha, down to 80 bytes! Try to beat me :P
60 in Golfscript. :P

Processing the new solution tomorrow.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Code Golf Contest #2
« Reply #6 on: July 23, 2014, 09:38:08 am »
Can we get some official clarification on input format, JWinslow23/willrandship? The main questions that come to mind are:

  • Are words/clusters composed of alphanumeric characters, any printable characters, or something in between?
  • Are leading, trailing, or duplicated (successive) spaces valid?

A good way to solidify all of these rules at once could be to specify a regular expression for valid input.

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 #2
« Reply #7 on: July 23, 2014, 12:48:02 pm »
Can we get some official clarification on input format, JWinslow23/willrandship? The main questions that come to mind are:

  • Are words/clusters composed of alphanumeric characters, any printable characters, or something in between?
  • Are leading, trailing, or duplicated (successive) spaces valid?

A good way to solidify all of these rules at once could be to specify a regular expression for valid input.
Well, if you use regular expressions, now you got TWO problems. :P

Words are made up of any printable characters except for the space. Trailing, leading, and repeating spaces are valid, but shall be deleted so there is only one space between words upon output.
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 #2
« Reply #8 on: July 23, 2014, 01:51:12 pm »



Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Code Golf Contest #2
« Reply #9 on: July 23, 2014, 03:29:52 pm »
Words are made up of any printable characters except for the space. Trailing, leading, and repeating spaces are valid, but shall be deleted so there is only one space between words upon output.

Are we sure this is the official ruling? Because when I asked willrandship his thoughts in IRC yesterday, he gave basically the opposite answers; words made up of alphanumeric characters only, and no trailing, leading, or repeating spaces. I personally prefer willrandship's view, because it gives a better chance to languages that don't have string splitting/regex functions and generally allows for more golfed/hacky solutions.
« Last Edit: July 23, 2014, 03:33:36 pm by Runer112 »

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 #2
« Reply #10 on: July 23, 2014, 05:30:03 pm »
Words are made up of any printable characters except for the space. Trailing, leading, and repeating spaces are valid, but shall be deleted so there is only one space between words upon output.

Are we sure this is the official ruling? Because when I asked willrandship his thoughts in IRC yesterday, he gave basically the opposite answers; words made up of alphanumeric characters only, and no trailing, leading, or repeating spaces. I personally prefer willrandship's view, because it gives a better chance to languages that don't have string splitting/regex functions and generally allows for more golfed/hacky solutions.
I kind of prefer the one words include those beginning with numbers, as stated in the examples in the OP. Either way, if numbers include alphanumeric characters after them as Runer said, my entry would be even more golfed and I would save about 12 characters. But I don't care.
« Last Edit: July 23, 2014, 05:32:05 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 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 #2
« Reply #11 on: July 23, 2014, 05:33:23 pm »
You know what? Let's just assume no trailing, leading, or repeating spaces, and all alphanumeric characters. That would bring my solution down from 465 bytes to about 280 bytes. :P
« Last Edit: July 23, 2014, 05:50:26 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 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 #2
« Reply #12 on: July 26, 2014, 06:36:40 pm »
2 more days left for submissions! Oh, and all winners in categories, think of possible next challenges.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline 3298

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +1/-0
    • View Profile
Re: Code Golf Contest #2
« Reply #13 on: July 27, 2014, 09:40:43 am »
Hello there, I have been reading some sections of Omnimaga for several months now (mostly the Casio and HP sections), and I finally decided to register so I can participate in this contest. After registering I found out that I need 5 posts to be able to send PMs, and I'm not the type of user who then posts in 5 random topics, so ... shall I just put my programs in spoilers, or what should I do?
(Edited to add: That's at least what some thread in the news section said. Now I see a PM icon below your user text which wasn't there before, but trying to use that will probably fail.)
I have written solutions in Java (190 bytes including a single-letter class name), XTend (a language implemented on top of Java; 160 bytes, with the same single-letter class name), Haskell (156 bytes, again including a single-letter function name) and SysRPL (79 bytes without name in compiled form, but due to the on-calc decompiler that's a feasible format for storage, you only lose pretty formatting and comments).
Even though not required, I tried throwing strings with non-alphanumeric characters and duplicate / leading / trailing spaces at my programs to see what happens. Java and XTend handle other characters just fine, the spaces are retained (can be fixed with 17 more bytes for Java and 9 for XTend). Haskell removes those spaces, but it might treat newlines and tabs as spaces. SysRPL keeps the spaces, but with 5 more bytes that's fixed. It also treats at least newlines as spaces, maybe tabs as well.
« Last Edit: July 27, 2014, 10:55:11 am by 3298 »

Offline DJ Omnimaga

  • Now active at https://codewalr.us
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55821
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Code Golf Contest #2
« Reply #14 on: July 27, 2014, 11:28:47 am »
Hi and welcome to the forums. To check if PMs work for you right now you could try to send a PM to yourself. Just go to the Inbox then click send message and put your nickname there. If it works then you probably can send PMs to everyone.

The limit used to be 5 posts because automatically registered bots would just advertise non-stop via PM, sometimes with very bad links. If you can't send PMs I guess you could also e-mail JWinslow23, if he gives it to you.
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF


Bandcamp|Reverbnation|Facebook|Youtube|Twitter