Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Map coordinates?

by Anonymous Monk
on Sep 02, 2019 at 16:36 UTC ( [id://11105453]=obfuscated: print w/replies, xml ) Need Help??

Hey Perl wizards. Any thoughts on what this translates to? TIA

@t = map{$_ *($_+($_-1))% 4}(2, 3, 4);$i=chr(0x34);$five=chr(55);print +"$i$five ".(@t[0]+@t[1]).($i/2).".".@t[0].chr(0x35).(@t[0]*3+1)."\n"; + @x= map{(srand(1)*$_)%9}(28,34,57);print @x[0].(@x[0]*2).(@x[0]*2*2/ +2)." ".chr(48).(@x[2]*3).".".(@x[2]+1).chr(0x30).((@x[1]%4)-3)."\n";

Replies are listed 'Best First'.
Re: Map coordinates?
by roboticus (Chancellor) on Sep 02, 2019 at 18:21 UTC

    Anonymous Monk:

    When you get some incomprehensible code, I'd suggest first running it through perltidy to get a better feel for what it looks like. You can then put in a few print statements to see what the values are initialized to. When I did so, I got this:

    $ perltidy pm_11105453.pl $ vi pm_11105453.pl <<< I then used vi to add some print statements to the result >>> $ cat pm_11105453.pl.tdy @t = map { $_ * ( $_ + ( $_ - 1 ) ) % 4 } ( 2, 3, 4 ); print "T=(", join(", ", @t), ")\n"; # What do we have in @t? $i = chr(0x34); $five = chr(55); print "I=$i, FIVE=$five\n"; # What's in $i and $five? print "$i$five " . ( @t[0] + @t[1] ) . ( $i / 2 ) . "." . @t[0] . chr(0x35) . ( @t[0] * 3 + 1 ) . "\n"; @x = map { ( srand(1) * $_ ) % 9 } ( 28, 34, 57 ); print "X=(", join(", ", @x), ")\n"; # What do we have in @x? print @x[0] . ( @x[0] * 2 ) . ( @x[0] * 2 * 2 / 2 ) . " " . chr(48) . ( @x[2] * 3 ) . "." . ( @x[2] + 1 ) . chr(0x30) . ( ( @x[1] % 4 ) - 3 ) . "\n"; $ perl pm_11105453.pl.tdy T=(2, 3, 0) I=4, FIVE=7 47 52.257 X=(1, 7, 3) 122 09.400

    After we run the code, we can see that it sets @t to (2, 3, 0) and @x to (1, 7, 3). If you had real code (instead of this obfuscated nonsense), you could analyze the functions map is applying to the incoming lists for initializing the @t and @x variables. I'd just edit the code and set @t and @x with the final values.

    After cleaning up the variable initializations, I'd then start looking for ways to simplify the various bits of code.

    For example, $i and $five are nearly unused--$five is used only once in a print statement, $i is used once in an expression and once in a print statement. So I'd delete those two variables and replace their uses with the corresponding values (4 for $i and 7 for $five). Variable deletion isn't always something I suggest, but sometimes it's the right tool.

    Next, I'd take advantage of any obvious algebraic simplifications, such as ( 4 / 2 ) with 2 and ( @x[0] * 2 * 2 / 2 ) with ( @x[0] * 2 ) and also replace constant function calls (such as the ones to chr()) with the results.

    Note: You can do a quick command-line experiment to find out the values from constant function calls, like this:

    $ perl -e 'print chr(0x35)' 5 $ perl -e 'print chr(0x30)' 0 $ perl -e 'print chr(48)' 0

    After doing this, and removing the now unnecessary print statements, I got:

    @t = (2, 3, 0); @x = (1, 7, 3); print "47 " . ( @t[0] + @t[1] ) . 2 . "." . @t[0] . '5' . ( @t[0] * 3 + 1 ) . "\n"; print @x[0] . ( @x[0] * 2 ) . ( @x[0] * 2 ) . " " . '0' . ( @x[2] * 3 ) . "." . ( @x[2] + 1 ) . '0' . ( ( @x[1] % 4 ) - 3 ) . "\n";

    From here, you could even replace all the references to @t and @x with their values, simplify further and boil the code down to:

    print "47 52.257\n"; print "122 09.400\n";

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Map coordinates?
by pme (Monsignor) on Sep 02, 2019 at 17:47 UTC
    Hi AM,
    use strict; use warnings; use Data::Dumper; my @t = map {$_ * ($_+ ($_- 1) ) % 4} (2, 3, 4); print '@t: ', Dumper(\@t), "\n"; # 2 3 0 my $i = chr(0x34); # '4' print "\$i: $i\n"; my $five = chr(55); # '7' print "\$five: $five\n"; print "$i$five " . ($t[0] + $t[1]) . ($i / 2) . "." . $t[0] . chr(0x35 +) . ($t[0] * 3 + 1) . "\n"; my @x = map { (srand(1) * $_) % 9 } (28, 34, 57); print '@x: ', Dumper(\@x), "\n"; # 1 7 3 print $x[0] . ($x[0] * 2) . ($x[0] * 2 * 2 / 2) . " " . chr(48) . ($x[ +2] * 3) . "." . ($x[2] + 1) . chr(0x30) . (($x[1] % 4) - 3) . "\n";
    The output for me is
    47 52.257 122 09.400
    HTH
Re: Map coordinates?
by swl (Parson) on Sep 03, 2019 at 10:05 UTC

    roboticus and pme solved the coordinates, but the code is likely missing the hemisphere. Convention is to treat it as (47 52.257 N, 122 09.400 E), which is in Mongolia. If it is treated as (47 52.257 N, 122 09.400 W) then it is near the I5 highway in Washington, USA, and this is more consistent with the variable names.

      Forgot to note that if it is southern hemisphere then it's a choice of Pacific or Indian Oceans.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found