Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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.

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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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 wandering the Monastery: (3)
As of 2023-09-26 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?