in reply to Golf: Movie style code cracker.
(+10 for any solution that runs more than 2.5 minutes (average time for a 'tense' movie scene (guestimate:)), for a 10 digit code.)
Uh. Two and a half minutes for guessing a 10 digit code? That's a challenge for the book writer. If I had a television, I would start zapping. In the cinema, I'd leave for the toilet, and get a beer. Anyways, 86 strokes.
perl -le'$#a=$d=pop;sub r{int rand 9}while($c<$d){$c++if$a[$c]==r;@a[$ +c..$d]=(r)x$d;print@a}' 10
Well, that displays each "guess" on a line. Making that into one line adds some chars - 97:
perl -e'$#a=$d=pop;sub r{int rand 9}while($c<$d){$c++if$a[$c]==r;@a[$c +..$d]=(r)x$d;print@a,"\r"}print$/' 10
But then, it's so fast you won't see the iterations... slowing down takes more chars (often seen in perl ;-)
perl -e'$#a=$d=pop;sub r{int rand 9}while($c<$d){$c++if$a[$c]==r;for(0 +..1e4){@a[$c..$d]=(r)x$d;print@a,"\r"}}print$/' 10
110 chars... I'm sure that can be reduced.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Golf: Movie style code cracker.
by Albannach (Monsignor) on Sep 13, 2008 at 16:59 UTC | |
|
Re^2: Golf: Movie style code cracker.
by BrowserUk (Patriarch) on Sep 14, 2008 at 03:26 UTC |