Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: The Perl Review

by jackdied (Monk)
on Feb 02, 2002 at 09:41 UTC ( #142904=note: print w/replies, xml ) Need Help??

in reply to The Perl Review

Here are mine,

Update : since I didn't understand anyone elses (give or take) I've added explanations to mine

The first is obvious (51 chars)
The second is stated in a couple different ways (43 chars, 50 chars obfu'd)

sub obvious{ # (explained : count from zero until Z, return the current count if w +e found the position we are looking for) # 1 2 3 4 5 6 #23456789012345678901234567890123456789012345678901234567890 $n=pop;for(;$n ne((0..9),(A..Z))[$a];$a++){}"$a"||0; }
This one is more fun, it uses bitwise arithmatic to get the solution. The commented line is the same as the first, but more obfu
sub fun { # (explained : reduce the numbers to their base2 (binary) # representation. we always care about the # lowest four bits ($n & 0x1111 is $n & 15). If the ord of # the number is in the A-Z range the 7th bit will be set # ($n >> 6) will be true. In this case, also include the # 6th bit in the number ($n & 31) instead of ($n & 15). # Since A-Z starts at ten, add 9 as well) # 1 2 3 4 5 6 #23456789012345678901234567890123456789012345678901234567890 $n=ord(pop);$a=($n>>6)?(($n&31)+9):($n&15); # same thing, but obfu # $n=ord(pop);$a=($n&(1<<(4+($n>>6)))-1)+($n>>6&&9); }

Enjoy, or not, at your leisure.


PS, posting with mozilla is the biggest pain in the ass ever. It tries to do smart things with wrapping in a text box, and translating spaces and returns for you with some AI that makes posting code hell.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142904]
[LanX]: ha ... just read an article saying that some US presidents in the past lost their nuclear codes
[LanX]: xD
[Corion]: The code is 00000000, as always, no?
[GotToBTru]: I remember hearing about somebody misplacing a list of code phrases or something
[marto]: 12345
[GotToBTru]: the "nuclear codes" are in the case cuffed to the wrist of some guy
[LanX]: not always

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-01-20 12:41 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.