Author Topic: [ENDED] Code Golf Contest #11  (Read 16685 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 #11
« on: September 22, 2014, 08:52:42 pm »
#MakeEleventyAThing :P

NEXT: Here
PREVIOUS: Here

Challenge 11

Problem

Create a program that, given an integer 0 through 999,999, does the "4 is magic" transformation. If you don't know what that is, this is it:
  • Take the number written out in English and count the number of letters (i.e. 21 is "twenty-one" is 9 letters, 102 is "one hundred two" is 13 letters, 9999 is "nine thousand nine hundred ninety-nine" is 33 letters).
  • If the result is 4, output "4 is magic." and exit.
  • Else, output "(original number) is (result)." and repeat step 1 with the result.
Example:
Code: [Select]
31 is 9.
9 is 4.
4 is magic.

-70% bonus if you actually display the number-words instead of the numbers.

Deadline
October 5, 2014, 1:00 AM EST

If any further clarification is needed, contact me. I'll try to make your troubles disappear. :P

Ruby
RankUserSizeDateCode
1Juju548-70%=164.49/23/2014 6:25:12 PM
Spoiler For Spoiler:
def w(n)
case n
when 0..19
["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"][n]
when 20..99
["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"][n/10-2]+(n%10==0?"":" "+w(n%10))
when 100..999
w(n/100)+" hundred"+(n%100==0?"":" "+w(n%100))
when 1000..999999
w(n/1000)+" thousand"+(n%1000==0?"":" "+w(n%1000))
end
end
a=gets.to_i
while a!=4
p w(a)+" is "+w(a=w(a).delete(" ").length)+"."
end
p"four is magic."

Golfscript
RankUserSizeDateCode
1JWinslow23360-70%=10810/4/2014 9:37:27 AM
Spoiler For Spoiler:
~{.20<{.12>["zero""one""two""three""four""five""six""seven""eight""nine""ten""eleven""twelve""thir""four""fif""six""seven""eigh""nine"]@="teen"@*+}{.100<{.10/2-["twen""thir""for""fif""six""seven""eigh""nine"]{"ty"+}%\=\10%a" "\++}{.1000<{.100/a" hundred "+\100%a+}{.1000/a" thousand "+\1000%a+}if}if}if" zero"%""+}:a;{.4=}{a." "/""+," is "\.n\}until" is magic"

Python
RankUserSizeDateCode
1Ivoah962-70%=288.69/26/2014 6:32:23 PM
Spoiler For Spoiler:
import sys
a = {1:' one',2:' two',3:' three',4:' four',5:' five',6:' six',7:' seven',8:' eight',9:' nine',10:' ten',11:' eleven',12:' twelve',13:' thirteen',14:' fourteen',15:' fifteen',16:' sixteen',17:' seventeen',18:' eighteen',19:' nineteen',20:' twenty',30:' thirty',40:' forty',50:' fifty',60:' sixty',70:' seventy',80:' eighty',90:' ninety',100:' hundred',1000:' thousand'}
def b(n):
 if n<=20:
  if n==0:return 'zero'
  else:return a[n].strip()
 else:
  c=''
  for d,e in enumerate(str(n)):
   i=10**(len(str(n))-d-1)
   j=int(e)
   if i==1e5:c+=a[j]+a[100]
   elif i==1e4:c+=a[j*10]
   elif i==1e3:
    if c[-3:]=='ten'and j!=0:c=c[:-4]+a[j+10]
    else:c+=a[j]
    c+=a[1e3]
   elif i==100:c+=a[j]+a[100]
   elif i==10:c+=a[j*10]
   elif i==1:
    if c[-3:]=='ten'and j!=0:c=c[:-4]+a[j+10]
    else:c+=a[j]
  c=c.strip()
  return c
n=sys.argv[1]
while True:
 f=len(''.join(b(n).split()))
 print b(n),'is',b(f)
 n=f
 if f==4:print b(4),'is magic!';break

Java
RankUserSizeDateCode
13298611-70%=183.310/4/2014 2:54:53 PM
Spoiler For Spoiler:
class G{static String[]x={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"},y={"twen","thir","four","fif","six","seven","eigh","nine"};static String t(int n){String s="";if(n>99){s=x[n/100]+" hundred ";n%=100;if(n==0)return s;}return s+(n<13?x[n]+" ":n<20?y[n-12]+"teen ":y[n/10-2]+"ty "+(n%10==0?"":x[n%10]+" "));}public static void main(String[]i){for(int n=Integer.parseInt(i[0]);{String s=n>999?t(n/1000)+"thousand "+(n%1000==0?"":t(n%1000)):t(n);int m=0;for(char c:s.toCharArray())if(c>64)++m;System.out.println(s+"is "+(n==4?"magic":m));if(n==4)break;n=m;}}}
2ben_g676-70%=202.89/28/2014 2:52:53 PM
Spoiler For Spoiler:
class e{public static void main(String[] a){int i=Integer.parseInt(a[0]);while(i!=4){a[0]=b(i).trim();if(a[0].length()==0)a[0]="zero";System.out.println(a[0]+" is "+(i=a[0].replace(" ","").length()));}System.out.println("four is magic");}static String b(int i){String[]n={"","one","two","three","four","five","six","seven","eight","nine","then","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"},m={"","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety","hundred"};if(i<20)return n;if(i<100)return m[i/10]+" "+n[i%10];if(i<1000)return b(i/100)+" hundred "+b(i%100);return b(i/1000)+" thousand "+b(i%1000);}}

C
RankUserSizeDateCode
13298630-70%=18910/4/2014 2:54:53 PM
Spoiler For Spoiler:
#include<stdio.h>
char*x[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"},*y[]={"twen","thir","four","fif","six","seven","eigh","nine"};int l;p(char*s){printf("%s",s);l+=strlen(s);}t(int n){if(n>99){p(x[n/100]);p(" hundred");--l;if(!(n%=100))return;p(" ");--l;}if(n<13)p(x[n]);else if(n<20){p(y[n-12]);p("teen");}else{p(y[n/10-2]);p("ty");if(n%=10){p(" ");--l;p(x[n]);}}}main(int c,char**v){int n=0;while(*(v[1]))n=10*n+*(v[1]++)-48;r:l=0;if(n>999){t(n/1000);p(" thousand");--l;if(n%1000){p(" ");--l;t(n%1000);}}else t(n);if(n-4){n=l;printf(" is %i\n",n);goto r;}p(" is magic\n");}
2ben_g861-70%=258.310/3/2014 3:52:36 AM
Spoiler For Spoiler:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char *m[]={"","one","two","three","four","five","six","seven","eight","nine","then","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};static const char *n[]={"","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety","hundred"};const char * w(int l, char* u){if(l==0){sprintf(u,"zero");return;}if(l<20){sprintf(u,"%s",m[l]);return;}if(l<100){sprintf(u,"%s %s",n[l/10],m[l%10]);return;}if(l<1000) {sprintf(u,"%s hundred ",m[l/100]);w(l%100,u+strlen(u));return;}w(l/1000,u);sprintf(u+strlen(u)," thousand ");w(l%1000,u+strlen(u));return;}int main(int argc,char *argv[]){int a=atoi(argv[1]);while(a!=4){char b[70]={0};int i=0;w(a,b);a=0;while(b!='\0'){if(b!=' ')a++;i++;}printf("%s is %i,\n",b,a);}printf("4 is magic.\n");}

SysRPL
RankUserSizeDateCode
13298493.5-70%=148.0510/4/2014 2:54:53 PM
Spoiler For Spoiler:
::
  { "twen" "thir" "four" "fif" "six" "seven" "eigh" "nine" }
  ' ::
    BINT100 #/ DUP#0=ITE DROPNULL$
    ::
      1GETLAMSWAP_ NTHCOMPDROP
      " hundred " &$
    ;
    SWAP DUP#0=csDROP
    BINT13 OVER#> case
    ::
      1GETLAMSWAP_ NTHCOMPDROP
      APPEND_SPACE &$
    ;
    BINT20 OVER#> case
    ::
      BINT11 #-
      3GETLAM SWAP NTHCOMPDROP
      "teen " &$ &$
    ;
    BINT10 #/ 3GETLAM SWAP#1-
    NTHCOMPDROP "ty " &$SWAP
    DUP#0=csedrp &$
    1GETLAMSWAP_ NTHCOMPDROP
    APPEND_SPACE &$ &$
  ;
  { "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve" }
  3NULLLAM{}_ BIND
  COERCE BEGIN
    DUP#0=ITE "zero "
    ::
      DUP # 3E8 #/
      DUP#0=csedrp 2GETEVAL
      2GETEVAL "thousand " &$SWAP
      2GETEVAL &$
    ;
    BINT0 OVERLEN$ #1+_ONE_DO
      OVERINDEX@ SUB$1#
      BINT64 #> IT #1+
    LOOP
    UNROT "is " &$SWAP
    BINT4 #=case
    ::
      RDROP SWAPDROP ABND
      "magic" &$
    ;
    OVER #>$ &$SWAP
  AGAIN
;

Language Ranking
RankLangUserSizeDate
1GolfscriptJWinslow2310810/4/2014 9:37:27 AM
2SysRPL3298148.0510/4/2014 2:54:53 PM
3RubyJuju164.49/23/2014 6:25:12 PM
4Java3298183.310/4/2014 2:54:53 PM
5C329818910/4/2014 2:54:53 PM
6PythonIvoah288.69/26/2014 6:32:23 PM
« Last Edit: June 11, 2015, 08:56:49 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 #11
« Reply #1 on: September 22, 2014, 10:14:50 pm »
Yay, got it to 562-70%=168.6 characters in Ruby.

EDIT: 559-70%=167.7 now. Also I have a few questions:
- Do I have to print "4 is 4" with an input of 4? (No would save a few bytes)
- "Ninety-nine" or "ninety nine"? Does it matter? (No would save one byte)
- Capital letter at the beginning? (No would save a few bytes)
« Last Edit: September 22, 2014, 10:23:18 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 #11
« Reply #2 on: September 23, 2014, 05:24:53 pm »
Yay, got it to 562-70%=168.6 characters in Ruby.

EDIT: 559-70%=167.7 now. Also I have a few questions:
- Do I have to print "4 is 4" with an input of 4? (No would save a few bytes)
- "Ninety-nine" or "ninety nine"? Does it matter? (No would save one byte)
- Capital letter at the beginning? (No would save a few bytes)
1. No, input of 4 means instant input of "4 is magic".
2. It shouldn't matter, but that's how I write numbers, usually. Do it if you want.
3. Whatever you want, but it's common courtesy to.
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 #11
« Reply #3 on: September 23, 2014, 07:03:16 pm »
Thanks, that answers my questions, I'll send you my 558-byte solution now.

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 #11
« Reply #4 on: September 23, 2014, 09:12:59 pm »
It works, and well at that! :thumbsup:
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 #11
« Reply #5 on: September 25, 2014, 07:19:49 pm »
Bump.

Woo, score of 111 in GS! :D
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Ivoah

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +3/-0
    • View Profile
    • Codinghobbit
Re: Code Golf Contest #11
« Reply #6 on: September 26, 2014, 09:17:31 am »
I made it in python, how do I enter it? p.s. this is my first time doing code golf
http://codinghobbit.no-ip.org
My Calcs:
TI-86 (now broken) $2
TI SR-56 - $0
TI-Nspire CX CAS - $152
TI-84+ Silver Edition - $56
TI-84+ Silver Edition - $0
TI-85 - $0
TI-73 Explorer VS - $10
ViewScreen - $3

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 #11
« Reply #7 on: September 26, 2014, 09:59:55 am »
You PM your code to JWinslow23.

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 #11
« Reply #8 on: September 26, 2014, 05:16:43 pm »
You PM your code to JWinslow23.
What he said ^^
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Ivoah

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +3/-0
    • View Profile
    • Codinghobbit
Re: Code Golf Contest #11
« Reply #9 on: September 26, 2014, 07:49:32 pm »
Message sent!
http://codinghobbit.no-ip.org
My Calcs:
TI-86 (now broken) $2
TI SR-56 - $0
TI-Nspire CX CAS - $152
TI-84+ Silver Edition - $56
TI-84+ Silver Edition - $0
TI-85 - $0
TI-73 Explorer VS - $10
ViewScreen - $3

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 #11
« Reply #10 on: September 26, 2014, 09:50:23 pm »
Message received!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Code Golf Contest #11
« Reply #11 on: September 28, 2014, 04:33:09 pm »
I would like to congratulate you for keeping a contest alive for this long (11 contests in such short period of time even though you are not a staff member). I know on IRC you said there weren't many entries for this one but the thing is that normally mini-contests die after 3 or 4 of them because the novelty wears off after a while (and in this case, school started). In fact, some recent contests like the revival of cage matches and the music contest never actually got any entry, if they even started at all. So good job. Some future suggestions to perhaps bring people back if they stopped participating:

-Put the contest theme inside the title (for example: Code Golf Contest #12: ThemeName)
-Perhaps do a small change of direction in terms of theme. Keep the same idea but explore themes that were not explored before
-Make the deadline 2 weeks for each contest if the regulars look busy
-Make sure that the rules are well planned for each contest (perhaps have somebody review them before the contest starts?) so that there are as few rule edits in the middle of the contest as possible and less loopholes. For example, for the olympic ring contest, the easiest way to win was to use HP PPL language.

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 #11
« Reply #12 on: September 28, 2014, 07:18:56 pm »
I would like to congratulate you for keeping a contest alive for this long (11 contests in such short period of time even though you are not a staff member). I know on IRC you said there weren't many entries for this one but the thing is that normally mini-contests die after 3 or 4 of them because the novelty wears off after a while (and in this case, school started). In fact, some recent contests like the revival of cage matches and the music contest never actually got any entry, if they even started at all. So good job. Some future suggestions to perhaps bring people back if they stopped participating:

-Put the contest theme inside the title (for example: Code Golf Contest #12: ThemeName)
-Perhaps do a small change of direction in terms of theme. Keep the same idea but explore themes that were not explored before
-Make the deadline 2 weeks for each contest if the regulars look busy
-Make sure that the rules are well planned for each contest (perhaps have somebody review them before the contest starts?) so that there are as few rule edits in the middle of the contest as possible and less loopholes. For example, for the olympic ring contest, the easiest way to win was to use HP PPL language.
Thank you for your kind remarks. I will try to use your suggestions.

In related news, the deadline of this contest is moved to October 5, and new contests will now be on Saturdays instead of Mondays.

As for new contests, here are the ones that are most likely to happen up until #15 (if I can squeeze another month or two out of this thing) (these are only ideas, not giving away every detail yet):
#12: Befunge Numbers (make optimal expressions in RPN that evaluate to input)
#13: A Picture's Worth 140 Characters (give a way to compress and decompress images into a 140 character or less string)
#14: Getting Out What You Don't Put In (output every character your program DOESN'T have, and nothing else)
#15: History Repeats Itself (make a program that, when repeated, outputs two different specified strings)

If you have any questions about these questions, contact me. I can try to clarify most of the details for you.
« Last Edit: September 28, 2014, 07:25:35 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 LDStudios

  • Coder Of Tomorrow
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 388
  • Rating: +41/-1
    • View Profile
    • LD Studios
Re: Code Golf Contest #11
« Reply #13 on: September 28, 2014, 08:19:21 pm »
Upcoming challenges sound challenging, but really cool! Good luck, I hope this contest keeps up!



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 #11
« Reply #14 on: September 28, 2014, 08:57:12 pm »
I would like to congratulate you for keeping a contest alive for this long (11 contests in such short period of time even though you are not a staff member). I know on IRC you said there weren't many entries for this one but the thing is that normally mini-contests die after 3 or 4 of them because the novelty wears off after a while (and in this case, school started). In fact, some recent contests like the revival of cage matches and the music contest never actually got any entry, if they even started at all. So good job. Some future suggestions to perhaps bring people back if they stopped participating:

-Put the contest theme inside the title (for example: Code Golf Contest #12: ThemeName)
-Perhaps do a small change of direction in terms of theme. Keep the same idea but explore themes that were not explored before
-Make the deadline 2 weeks for each contest if the regulars look busy
-Make sure that the rules are well planned for each contest (perhaps have somebody review them before the contest starts?) so that there are as few rule edits in the middle of the contest as possible and less loopholes. For example, for the olympic ring contest, the easiest way to win was to use HP PPL language.
Thank you for your kind remarks. I will try to use your suggestions.

In related news, the deadline of this contest is moved to October 5, and new contests will now be on Saturdays instead of Mondays.

As for new contests, here are the ones that are most likely to happen up until #15 (if I can squeeze another month or two out of this thing) (these are only ideas, not giving away every detail yet):
#12: Befunge Numbers (make optimal expressions in RPN that evaluate to input)
#13: A Picture's Worth 140 Characters (give a way to compress and decompress images into a 140 character or less string)
#14: Getting Out What You Don't Put In (output every character your program DOESN'T have, and nothing else)
#15: History Repeats Itself (make a program that, when repeated, outputs two different specified strings)

If you have any questions about these questions, contact me. I can try to clarify most of the details for you.
Yep, what DJ said. Congrats for keeping it up for 11 iterations and getting many people to enter each time! I entered in every contest so far, and the ideas you gave for the next ones looks pretty interesting and challenging.

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.