Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Arrays and bitwise operators

by iamcal (Friar)
on Jun 19, 2001 at 19:03 UTC ( [id://89659]=note: print w/replies, xml ) Need Help??


in reply to Arrays and bitwise operators

# # this is a long decon. the aim is to show how to deconstruct japhs in + general # # # first we format it cleanly # for$a(27..35,9..12){ for$b(17..21,3..8){ for$c(11..30){ $d = abs($c-$a)+$b; $e = $b^$a|$c; push @a,$b+$c; } } } map{$_+=43}@a; @w=map{chr}@a; $x=[11,13,32,33,41,45,50,60,83,90,71,69,269]; $y=[244,231,240,468,454,463,806,744,789,246]; @z=map{$w[$_]}@$x,@$y,1948; @c{@z}=(1)x$#z; @z[0..keys%c]=sort keys%c; $q=[[4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]]; map{ print map{lc@z[$_]}@$_; print chr 0x20 }@$q; # # now look at that loop - half of that code doesn't do anything. # clean it up and see that we're getting a big array of numbers # into @a (2859 elements) # for $a(1..13){ for $b(27..31,13..18){ for $c(1..20){ push @a,$b+$c; } } } map{$_+=43}@a; @w=map{chr}@a; $x=[11,13,32,33,41,45,50,60,83,90,71,69,269]; $y=[244,231,240,468,454,463,806,744,789,246]; @z=map{$w[$_]}@$x,@$y,1948; @c{@z}=(1)x$#z; @z[0..keys%c]=sort keys%c; $q=[[4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]]; map{ print map{lc@z[$_]}@$_; print chr 0x20 }@$q; # # we now notice that the first map just adds 43 to each element in # @a. we can do it earlier and dump the map. the next map just convert +s # the numbers in @a into characters in @w. since we see that @a isn't # used again, we can skip this and populate @w in the loop. # for $a(1..13){ for $b(27..31,13..18){ for $c(1..20){ push @w,chr($b+$c+43); } } } $x=[11,13,32,33,41,45,50,60,83,90,71,69,269]; $y=[244,231,240,468,454,463,806,744,789,246]; @z=map{$w[$_]}@$x,@$y,1948; @c{@z}=(1)x$#z; @z[0..keys%c]=sort keys%c; $q=[[4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]]; map{ print map{lc@z[$_]}@$_; print chr 0x20 }@$q; # # next we see that the array refs $x and $y are only use once. let's # cancel them down # for $a(1..13){ for $b(27..31,13..18){ for $c(1..20){ push @w,chr($b+$c+43); } } } @z=map{$w[$_]}(11,13,32,33,41,45,50,60,83,90,71,69,269,244,231,240,468 +,454,463,806,744,789,246,1948); @c{@z}=(1)x$#z; @z[0..keys%c]=sort keys%c; $q=[[4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]]; map{ print map{lc@z[$_]}@$_; print chr 0x20 }@$q; # # so @z just gets a slice from @w. so let's use slice syntax :) # while we're at it, let's expand (1)x$#z since we know the value of $ +#z # without @w really being used, we can just assign@z directly # @z = split//,'RTTUJNSJNUUSRLRHPUKAOCNE'; @c{@z}=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); @z[0..keys%c]=sort keys%c; $q=[[4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]]; map{ print map{lc@z[$_]}@$_; print chr 0x20 }@$q; # # let's ignore the @c{@z} for a minute # $q is just used as an array ref to confuse us. let's turn it into an + array # @z = split//,'RTTUJNSJNUUSRLRHPUKAOCNE'; @c{@z}=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); @z[0..keys%c]=sort keys%c; @q=([4,13,11,12],[0,7,8,12,3,2,10],[9,2,10,6],[3,0,1,5,2,10]); map{ print map{lc@z[$_]}@$_; print chr 0x20 }@q; # # that last map is just looping four times - let's expand it out # @z = split//,'RTTUJNSJNUUSRLRHPUKAOCNE'; @c{@z}=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); @z[0..keys%c]=sort keys%c; print map{lc@z[$_]}(4,13,11,12); print chr 0x20; print map{lc@z[$_]}(0,7,8,12,3,2,10); print chr 0x20; print map{lc@z[$_]}(9,2,10,6); print chr 0x20; print map{lc@z[$_]}(3,0,1,5,2,10); print chr 0x20; # # but i recognise those remaining maps - they're just array slices! # we can remove those 'lc' calls for reabablity too # and of course, chr 0x20 is just ' ' # @z = split//,'RTTUJNSJNUUSRLRHPUKAOCNE'; @c{@z}=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); @z[0..keys%c]=sort keys%c; print @z[4,13,11,12]; print ' '; print @z[0,7,8,12,3,2,10]; print ' '; print @z[9,2,10,6]; print ' '; print @z[3,0,1,5,2,10]; print ' '; # # so for each word we print out a slice of @z. right # what was that @c{@z} doing. well, it's assigning 1 to # each hash elmement with a key in @z. keys%c is 14 so # substitute that too # @z = split//,'RTTUJNSJNUUSRLRHPUKAOCNE'; for(@z){$c{$_}=1;} @z[0..14]=sort keys%c; print @z[4,13,11,12]; print ' '; print @z[0,7,8,12,3,2,10]; print ' '; print @z[9,2,10,6]; print ' '; print @z[3,0,1,5,2,10]; print ' '; # # amlost there now... # then the 15 sorted keys are shoved back into @z # but there are only 14 keys. so one element of @z is killed # since we now know the contents of @z, let's show that # @z = ('A','C','E','H','J','K','L','N','O','P','R','S','T','U','','H',' +P','U','K','A','O','C','N','E'); print @z[4,13,11,12]; print ' '; print @z[0,7,8,12,3,2,10]; print ' '; print @z[9,2,10,6]; print ' '; print @z[3,0,1,5,2,10]; print ' '; # # well it's obvious now, right. let's finish up. removing @z # print "JUST"; print ' '; print "ANOTHER"; print ' '; print "PERL"; print ' '; print "HACKER"; print ' '; # # and combining # print "JUST ANOTHER PERL HACKER";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://89659]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-06-20 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.