Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher.
From previous experience, the official CompSoc programming competitions have been too serious, and I'd thought it'd be nice if we could have some simple ones, without arbitrary restrictions.
You're free to use whatever language you want, although if I can't get it working within a reasonable amount of time on my desktop, it won't be counted. Non-standard libraries are out, too.
If there's enough interest in this, I might be persuaded to run it weekly, with the scoring running for each term.
Due to the open-endedness of this, it's necessary to have a "please don't cheat" rule.. please don't. :)
Given a string, produce the series of button-presses required to type it on a mobile 'phone, using the space character for "pause". For example, ponies rock:
| p | o | n | i | e | s | r | o | c | k | ||
| 7 | 666 | 66 | 444 | 33 | 7777 | 0 | 777 | 666 | 222 | 55 | |
ie. 7666 66444337777077766622255
Optional pauses must not be included. Only the lower-case a thru z and space need to be supported.
The input will be provided through stdin and as a paramater (if appropriate), use what you wish, ie. bash:~$ echo 'ponies rock' | your-program 'ponies rock'. Here your-program may include an interpreter name (within reason), ie. php my_entry.php.
Output must be on stdout, any non-numeric/space characters will be ignored.
If you've really forgotten, a {pause} is required if the next group of numbers is from the same key (any key, including zero-space), as in the example above (six is used twice in a row), and the keypad is:
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 |
| abc | def | ghi | jkl | mno | pqrs | tuv | wxyz | {space} |
As One, except you may enter multiple times (ie. in multiple languages).
Deadline for submissions, by e-mail (please include MPC or at least "programming" in the subject), is 10pm Monday, 6th August 2007.
Given an integer i, 2 < i < 30000, draw a diamond with this number of lines above the centre, for instance, an input of “3” on standard input, your program should produce the following on standard output:
/\ /##\ /####\ <######> \####/ \##/ \/
The characters used above are “ ” (Space), “/” (Solidus), “\” (Reverse Solidus), “#” (Number Sign), “<” (Less-Than Sign) and “>” (Greater-Than Sign).
The space at the beginning of the lines and the line terminators are significant, other whitespace is not.
Submissions will be sorted by code length (octets) ((possibly) including the command-lines (that you will provide) necessary to make it work), as measured by the judge, “shortest” first.
You may make one submission in total, in a language of your choice. A point will be awarded to you if you are the “shortest” in your language, assuming there was competition, otherwise you will not be awarded.
In addition to this, a point will be awarded for the “shortest” solution overall.
Extra points might be awarded for stupid, masochistic or otherwise impressive solutions.
Submissions for this challenge closed 8pm Sunday, 22nd October 2006.
| Points | Entrant | Language | Length | Entry |
|---|---|---|---|---|
| 2 | Jeremy | Perl | 68 | perl -pe'$c=$_;$_="<>";while($c--){s|^| |gm;s|<(#*)>|/$1\\\n<#$1#>\n \\$1/|}' |
| 1 | cavehippo | C | 168 | main(){int n,x,i=0,I;char l[(x=scanf("%d",&n)+n*2)+2];for(;i<x;memset(l,35,puts(memset(l,32,I))))l[x+1-(I=abs(n-i))]=0,l[(x+n-i)%x]=n^i?47:60,l[(n+i)%x+1]=n^i++?92:62;} |
| Entrant | Language | Length | Entry |
|---|---|---|---|
| bucko | Perl | 77 | perl -e'$a=<>;$_="<> ";s|^( *.#*)|$1##|mg,/( *)/,$_="$1 /\\ $_$1 \\/ "while$a--;print' |
| whythehell | False | 132 | [$0=$[@@60$2+b;!@]?~[47 92b;!1O2+1O1-1O2+O!92 47b;!]?%%][2O[$0=~][32,1-]#%\,2O[$0=~]["##"2-]#%," "]b:0$[^$10=~][48-\10*+]#%2O!% |
| whythehell | Bash | 198 | read l for((m=1,i=0,k=2;i<=l*2;m-=++i>l?1:-1)) do for((j=1+l+m;j--;));do echo -en "\x$((j<2*m?23:20))";done;echo done|sed "s, #, \\\\,;s,^#\(.*\)#$,<\1>,;s,#$,/ ,;1,+${l}s,/,\\\\,;1,+${l}s,\\\\,/," |
| whythehell | C++ | 213 | #include <cstdio> int main(){for(int p,y=scanf("%d",&p),z=0,a=p*2+2,w=0,f=0;z<a*a+w;f=++z/(a+1)==p)putchar(z%(a+1)==a?f?z+=w=3*a+3:0,10:((z%(a+2)==(p+1)?(y=!w,f?62:92):(z%a==(p+(w?2:0))?(y=w,f?60:47):y?32:35))));} |
| Faux | C | 219 | #define p(x) putchar(x); #define h r(i*2,35) #include<cstdio> r(n,c){while(n--)p(c);}main(){int i=0,a;scanf("%d",&a);for(;i<a;i++){r(a-i,32);p(47)h;p(92)p(10)}p(60)h;p(62)p(10)while(i-->0){r(a-i,32);p(92)h;p(47)p(10)}} |
| Faux | C++ | 227 | #include<iostream> #include<string> #define r std::string #define h r(i*2,'#') #define c std::cout #define j c<<r(a-i,' ') int main(){int i=0,a;std::cin>>a;for(;i<a;++i)j+"/"+h+"\\\n";c<<"<"+h+">\n";while(i-->0)j+"\\"+h+"/\n";} |
| icStatic | C++ | 234 | #define E return #define X(l,r) for(a=0;a++<r;)Y(l); #define Y putchar #define Z(a,b) {X(32,t-c)Y(d?a:b);X(35,c*2)Y(d?b:a);Y(10);} int c=0,t,a,d=0;void main(){std::cin>>t;j:if(c-t)Z(92,47)else{Z(62,60)d=1;}if(d&!c)E;c+=d?-1:1;goto j;} |
| Sudilos | C | 291 | #include <stdio.h> #include <stdlib.h> #define M main M(int i,int j,int k){i==2?M(4,0,atoi(((char**)j)[1])):((i<0)?j>0?printf(k),M(-1,j-1,k):1:(i-=4,(j<1&i>k)|(j>0&i<0)?1:(M(-1,k-i," "),M(-2,1,j?"\\":i==k?"<":"/"),M(-4,i*2,"#"),M(-6,1,j?"/\n":i==k?j=!j,">\n":"\\\n"),M(i-(j?1:-1)+4,j,k))));} |
| Faux | Java | 335 | class O{static String r(String s,int e){String o="";while(e-->0)o+=s;return o;}public static void main(String[]g){int a=new java.util.Scanner(System.in).nextInt(),i=0;for(;i<a;i++)System.out.println(r(" ",a-i)+"/"+r("#",i*2)+"\\");System.out.println("<"+r("#",i*2)+">");while(i-->0)System.out.println(r(" ",a-i)+"\\"+r("#",i*2)+"/");}} |
The Speshul Award goes to whythehell for beating me in multiple crazy languages. An honourable mention to cavehippo, who's code only works on certain machines running certain, unique versions of gcc.
Please contact me via. IRC.
I have: no responsibility for anything, final word, the right to change the rules for fun and profit, no affiliation with CompSoc, etc.