http://www.perlmonks.org?node_id=31571

As you can see, this is not obfuscated and the game is quite stupid. This is in fact my try to make Perlists and Pythonists friends again.

Juste note that the Perl code could be way shorter, whereas the Python one could not. :-)

###################################################################### # Python # Perl # ###################################################################### q = -1 ; #=; $n = int rand 1001; print '? '; q# import whrandom ; i = 1 #; while(<>){ q# n = whrandom.randint(0,1000) #; $i++; q# while q != n : #; last if $_ == $n; q# q = int(raw_input('? ')) #; print 'Too '; q# if q == n : #; print ($_>$n?'big':'small'); q# break #; print "\n? "; q# print 'Too', #; } q# if q > n : #; print "You won in $i tries\n"; q; print 'big' # else: # print 'small' # i = i + 1 # print 'You won in', i, 'tries' #;

You might as well imagine this as documenting Python code in Perl, and Perl code in Python, for beginners in any of the two languages.

Replies are listed 'Best First'.
(ar0n: laziness) RE: 'nother P(erlython) Hacker
by ar0n (Priest) on Sep 10, 2000 at 05:08 UTC
    i'm too lazy to play the game myself:
    ;$*=1000;$@=int rand$*;sub _{print@_}$%= $*/2;for(;$%!=$@;$-++){;($%>$@)?$*=$%:$: =$%;$%=int(($%>$@)?$%-(($*-$:)/2):$%+($* -$:)/2);}_("Answer is $% ($- tries)\n");

    -- ar0n (lazy bastard)

RE: 'nother P(erlython) Hacker
by mt2k (Hermit) on Sep 10, 2000 at 03:49 UTC
    My version:
    $n=int(rand(1001));print'>'; while(<>){++$i;last if$_==$n;$_>$n?$n--:++$n;print'Too ',$_>$n?'big':' +small',"\n>";} print"Won in $i tries\n";