Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

'nother P(erl|ython) Hacker

by BooK (Curate)
on Sep 08, 2000 at 14:18 UTC ( #31571=obfuscated: print w/ replies, xml ) Need Help??

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.

Comment on 'nother P(erl|ython) Hacker
Download Code
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";
(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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://31571]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-12-18 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls