Author Topic: [ENDED] Code Golf Contest #7  (Read 25838 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 #7
« on: August 25, 2014, 04:52:22 pm »
This must be your lucky day!

NEXT: Here
PREVIOUS: Here

Challenge 7

Problem
Make a program that, given an input as a string, outputs the (newline-separated) indexes of the string where the letters that make up the word "code" appear (one of each in order). For example, for input such as:

School is about to start! Be sure to do your homework!

the letters that make up the word "code" are marked by asterisks here:

School is about to start! Be sure to do your homework!
 ^ ^                                 ^          ^


(in that exact order) (search should be case-insensitive if possible)
And the output would be:

2
4
38
49


(the positions of the characters in the string).
Simply output ONLY 0 if such is impossible.

Deadline
September 1, 2014, 1:00 AM EST

If any further clarification is needed, contact me. I will try to search for order. (honestly, nobody comments about the puns anymore :P )

Java
RankUserSizeDateCode
132981898/29/2014 12:16:14 PM
Spoiler For Spoiler:
class G{public static void main(String[]s){String o="";int p=0;for(char c:"code".toCharArray()){p=s[0].toLowerCase().indexOf(c,p);if(p<0){o="0";break;}o=o+(p+1)+"\n";}System.out.print(o);}}
2pimathbrainiac2688/25/2014 6:57:57 PM
Spoiler For Spoiler:
import java.util.Arrays;public class C7{public static void main(String[] args){String s=Arrays.toString(args);int a,b,c,d;a=s.indexOf('c')-1;b=s.indexOf('o')-1;if(b>a){c=s.indexOf('d')-1;if(c>b){d=s.indexOf('e')-1;if(d>c){System.out.print(a+"\n"+b+"\n"+c+"\n"+d);}}}}}

Golfscript
RankUserSizeDateCode
1JWinslow23558/25/2014 7:22:08 PM
Spoiler For Spoiler:
0:a;{.96>32 0if-}/]"CODE"{1$?.a+:a\@>}/;]..$=*.{n*}0if

Nspire Lua
RankUserSizeDateCode
1Jens_K828/30/2014 6:52:41 AM
Spoiler For Spoiler:
function cgc7(s)
i=0
repeat
p=s:find(("c.*o.*d.*e"):sub(i*3+1),p)or 0
print(p)i=i+1
until p*(4-i)<1
end
2Adriweb1048/26/2014 9:43:18 AM
Spoiler For Spoiler:
function y(s)t={}for a=1,4 do t[#t+1]=s:find(("code"):sub(a,a),t[#t])end print(#t<4 and 0 or table.concat(t,"\n"))end end

TI-83+ BASIC
RankUserSizeDateCode
1JWinslow23508/26/2014 10:54:23 AM
Spoiler For Spoiler:
Input Str1
1
For(X,1,4
inString(Str1,sub("CODE",X,1),Ans
If not(Ans
ClrHome
Disp Ans
If not(Ans
Return
End

Axe
RankUserSizeDateCode
1JWinslow231528/28/2014 9:43:23 AM
Spoiler For Spoiler:
"CODE"->Str1
input->M
0->A
For(X,0,3)
If inData({X+Str1},A+M)
+A
End
!If ->A
4->X
ClrHome
End
Disp A>Dec,i
End

XTend
RankUserSizeDateCode
132981638/29/2014 12:16:14 PM
Spoiler For Spoiler:
class G{def static void main(String[]s){var o=""var p=0;for(c:"code".toCharArray){p=s.head.toLowerCase.indexOf(c,p)if(p<0){print(0)return}o=o+(p+1)+"\n"}print(o)}}

Haskell
RankUserSizeDateCode
132981748/29/2014 12:16:14 PM
Spoiler For Spoiler:
import Data.Char
g i=putStr o where(_,o,_)=foldl h(i,"",0)"code"
h(s,r,n)c=if t/=""then(tail t,r++(show m)++"\n",m)else(t,"0",m)where(d,t)=span((/=c).toLower)s;m=n+1+length d

SysRPL
RankUserSizeDateCode
132981048/29/2014 3:04:40 PM
Spoiler For Spoiler:
::
  NULL$SWAP ONESWAP "code"
  BEGIN
    2DUP CAR$
    2DUP 7PICK POSCHR UNROT
    CHR># BINT32 #- #>CHR 6ROLL POSCHR
    2DUP 2#0=OR ITE #MAX #MIN
    DUP#0=csedrp :: RDROP 3DROP tok0 ;
    DUP4UNROLL #>$ NEWLINE&$
    5ROLL SWAP&$ 4UNROLL CDR$
  DUPNULL$? UNTIL 3DROP
;

C
RankUserSizeDateCode
132981698/30/2014 9:50:11 AM
Spoiler For Spoiler:
#include<stdio.h>
main(int m,char**i){++i;int o[]={0,0,0,0},c=0,n=1;for(;**i&&c<4;++n)if("code"[c]==(*(*i)++|32))o[c++]=n;for(c=o[3]!=0?0:3;c<4;++c)printf("%i\n",o[c]);}
2alberthrocks1888/29/2014 4:09:31 PM
Spoiler For Spoiler:
#define f for(i=0;i<4;i++){
main(){char *s,*p,c[5]="code",r[4],i=0,x=0;scanf("%m[^\n]s",&s);f p=strchr(s+x,c);if(!p){printf("0\n");exit(0);}x=p-s;r=x+1;}i=0;f printf("%i\n",r);}}


Python3
RankUserSizeDateCode
1willrandship998/30/2014 3:07:52 AM
Spoiler For Spoiler:
b=0;e='';f=0
for c in input():
 b+=1;
 if'code}'[f]==c:e+='\n'+str(b);f+=1
if len(e)<8:e=0
print(e)
2alberthrocks1168/29/2014 4:09:31 PM
Spoiler For Spoiler:
import sys;s=input().lower();i=0;a=""
for l in "code":i=s.find(l,i);i<0 and sys.exit('0');a+=str(i+1)+"\n"
print(a)


Bash
RankUserSizeDateCode
1alberthrocks1818/29/2014 4:09:31 PM
Spoiler For Spoiler:
x(){ echo "0";exit 1; };s="code";r[0]=0;read i;for n in {0..3};do p=${r[-1]};r[$n]=`expr index "${i:${r[-1]}}" "${s:$n:1}"`||x;r[$n]=`expr ${r[-1]} + $p`;done;printf '%s\n' ${r
  • }[/l][/l][/l][/l]


Ruby2
RankUserSizeDateCode
1Juju778/29/2014 8:20:46 PM
Spoiler For Spoiler:
p 0if !gets.match(/.*?(c).*?(o).*?(d).*?(e).*/i){|a|4.times{|b|p a.end(b+1)}}


Perl
RankUserSizeDateCode
1willrandship968/30/2014 3:07:52 AM
Spoiler For Spoiler:
for(split//,<>){$b++;$d=substr"code",$f,1;if($d eq$_){$e.=$b."\n";$f++}}$_=length$e<8?0:$e;print


Language Ranking
RankLangUserSizeDate
1TI-83+ BASICJWinslow23508/26/2014 10:54:23 AM
2GolfscriptJWinslow23558/25/2014 7:22:08 PM
3Ruby2Juju778/29/2014 8:20:46 PM
4Nspire LuaJens_K828/30/2014 6:52:41 AM
5Perlwillrandship968/30/2014 3:07:52 AM
6Python3willrandship998/30/2014 3:07:52 AM
7SysRPL32981048/29/2014 3:04:40 PM
8AxeJWinslow231528/28/2014 9:43:23 AM
9XTend32981638/29/2014 12:16:14 PM
10C32981698/30/2014 9:50:11 AM
11Haskell32981748/29/2014 12:16:14 PM
12Bashalberthrocks1818/29/2014 4:09:31 PM
13Java32981898/29/2014 12:16:14 PM
[/list]
« Last Edit: June 11, 2015, 08:54:53 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 pimathbrainiac

  • Occasionally I make projects
  • Project Author
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1731
  • Rating: +136/-23
  • dagaem
    • View Profile
Re: Code Golf Contest #7
« Reply #1 on: August 25, 2014, 07:56:25 pm »
268 bytes of Java! YAYGIMMIEGIMMIE!
I am Bach.

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 #7
« Reply #2 on: August 25, 2014, 08:26:02 pm »
Nice for a first submission, pimath. :)
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 #7
« Reply #3 on: August 26, 2014, 07:04:02 am »
162 NSpire Lua, but still working on it



Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Code Golf Contest #7
« Reply #4 on: August 26, 2014, 08:19:54 am »
Got a 101-bytes one in Lua.

Also, that's assuming you want to have displayed only 0 if it's not possible, and nothing else printed during the process.
(Because if other number can appear in the loop as well as 0, well, I got a shorter one.)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Code Golf Contest #7
« Reply #5 on: August 26, 2014, 08:37:11 am »
44 bytes in z80 ASM.

EDIT : 42 bytes

EDIT 2 : 41 bytes

EDIT 3 : 38 bytes (unstoppable me)

EDIT 4 : 37 bytes

EDIT 5 : 36 bytes
« Last Edit: August 26, 2014, 09:01:14 am by Matrefeytontias »

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 #7
« Reply #6 on: August 26, 2014, 10:24:24 am »
47 43 42 bytes of Ruby here.
« Last Edit: August 26, 2014, 10:29:23 am 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 #7
« Reply #7 on: August 26, 2014, 10:28:55 am »
Got a 101-bytes one in Lua.

Also, that's assuming you want to have displayed only 0 if it's not possible, and nothing else printed during the process.
(Because if other number can appear in the loop as well as 0, well, I got a shorter one.)
Only 0.
And WOW, some of these submissions are even smaller than my Golfscript solution! :P First time ever that a lang other than CJam has beaten Golfscript.
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 #7
« Reply #8 on: August 26, 2014, 10:31:08 am »
Oh wait, my solution throws an error instead of printing 0. Whatever, that just adds 8 bytes.

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 Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Code Golf Contest #7
« Reply #9 on: August 26, 2014, 10:38:05 am »
What do you mean by printing 0 actually ? I didn't get that part.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Code Golf Contest #7
« Reply #10 on: August 26, 2014, 10:43:28 am »
If "c" "o" "d" "e" can't be found (in that order) in the string, then print 0 and nothing else.

Anyway, for my Lua solution, wrapped in a function, it's 121 bytes, then.
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

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 #7
« Reply #11 on: August 26, 2014, 11:52:49 am »
I got 50 bytes in TI-BASIC. I worked WAY too hard on it. O.O
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Code Golf Contest #7
« Reply #12 on: August 26, 2014, 12:55:01 pm »
Oh. Well I'll have to do it again then.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Code Golf Contest #7
« Reply #13 on: August 27, 2014, 08:44:03 pm »
Lately, I've thought o fmakinga Lua "preprocessor" thingy/language that would feature much shorter things but in the end it would be run as Lua.
It might be called GolfLua, who knows (any idea ? :P)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline LDStudios

  • Coder Of Tomorrow
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 388
  • Rating: +41/-1
    • View Profile
    • LD Studios
Re: Code Golf Contest #7
« Reply #14 on: August 28, 2014, 07:58:43 am »
Lately, I've thought o fmakinga Lua "preprocessor" thingy/language that would feature much shorter things but in the end it would be run as Lua.
It might be called GolfLua, who knows (any idea ? :P)

Set up as a library like BetterLuaAPI but designed for golf? That would be really cool, I might do something similar.