Hi all,
This is the first JAPH I've ever written. It's simple, but (AFAIK) has an original idea.
use Time::HiRes 'usleep';++$|;$s='rekcah lreP rehtona tsuJ';@v= (65..90,97..122,32);do{do{print$_=sprintf'%c',$v[rand@v];usleep 2000;print"\b"}while$_ ne substr$s,-1;chop$s;print}while$s
Basically what it does is it loops randomly through A-Za-z and a space until it finds the correct character for that spot and then moves on to the next character. I added a small delay too so one can see it shuffling through the characters instead of the boring, ordinary way of instantaneous appearance of the whole string. ;)
Update: An indented and commented version with whitespaces
use Time::HiRes 'usleep'; # to get usleep ++$|; # same as $| = 1, i.e. enabling autoflush $s='rekcah lreP rehtona tsuJ'; # "Just another Perl hacker", reversed @v=(65..90,97..122,32); # ASCII values for A-Z, a-z and a whitespace do{ do{ # setting $_ to a random letter from @v, printing it print $_ = sprintf '%c',$v[rand@v]; # sleeping for a while usleep 2000; # printing \b, a backspace print"\b" #..while $_ is not the last letter of $s } while $_ ne substr $s,-1; # shortening $s by one, i.e. moving on to the next letter chop $s; # printing $_, i.e. the correct letter for that space print #..while there's still something to print in $s } while $s
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Brute-force JAPH
by Lawliet (Curate) on Jan 27, 2009 at 23:26 UTC | |
by jh- (Scribe) on Jan 27, 2009 at 23:47 UTC | |
by Lawliet (Curate) on Jan 27, 2009 at 23:52 UTC | |
by jh- (Scribe) on Jan 28, 2009 at 05:12 UTC | |
by ambrus (Abbot) on Jan 28, 2009 at 12:11 UTC |