Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: reducing the number of lines

by choroba (Abbot)
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 taking refuge in the Monastery: (13)
As of 2014-07-25 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls