Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Golf: Movie style code cracker.

by shmem (Chancellor)
on Sep 12, 2008 at 23:34 UTC ( [id://711039]=note: print w/replies, xml ) Need Help??


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
    Just throw in a ninja battle, 2.5 minutes will go by in no time!

    --
    I'd like to be able to assign to an luser

Re^2: Golf: Movie style code cracker.
by BrowserUk (Patriarch) on Sep 14, 2008 at 03:26 UTC

    I like your 110 stroke version. Though I'd have to penalise for never producing a '9' in the final code.

    However, on my system at least, you could trade the extra stroke of rand 10 for ommitting the final print$/ as the system supplies one when the program ends.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://711039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found