Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: reducing the number of lines

by choroba (Canon)
on Jan 11, 2013 at 17:25 UTC ( #1012930=note: print w/ replies, xml ) Need Help??


in reply to reducing the number of lines

For those interested, this is the code I used to compare the new solution to the original one:

#!/usr/bin/perl use warnings; use strict; use feature 'state'; use integer; use Test::More; my (@s_rev, @s); my ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i); try() for 1 .. 1000; done_testing(); sub new { ## Insert your code here return ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i, \@s_rev, \@ +s); } sub try { init(1); my @r0 = orig(); init(0); my @r1 = new(); is_deeply(\@r0, \@r1); } sub init { state @keep; $_ = shift; if ($_) { ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i, @s_rev) = map { rand 8 } 1 .. 12 + rand 20; @s = (0 .. 3 + rand 20); @keep = ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i, [@s_re +v], [@s]); } else { ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i) = @keep; @s = @{ $keep[-1] }; @s_rev = @{ $keep[-2] }; } } sub orig { if ($l < $k) { if ($s_rev[$d + 1] == 0 && $k - 2 > 0){ $s_rev[$d + 1] = $k - 2; } $h = $s[$b] == 0 ? 0 : $s[$b] - 1; $s[$b1] = max($k, $lt); $c = 2; $j++; } elsif ($l > $k) { if($s[$b + 1] == 0 && $l - 2 > 0){ $s[$b + 1] = $l - 2; } $h = $s[$b] == 0 ? 0 : $s[$b] - 1; $s[$b1] = max($l, $kt); $c = 1; $i++; } else { if($s[$b+1] == 0 && $k - 2 > 0){ $s[$b+1] = $k-2; } $s[$b1] = max($k, $lt); $h = 0; $c = 0; } return ($l, $k, $d, $b, $c, $j, $h, $b1, $lt, $kt, $i, \@s_rev, \@ +s); } sub max{ my ($x, $y) = @_; return $x > $y ? $x : $y; }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: reducing the number of lines
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2015-07-06 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls