aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-146/james-smith/perl/ch-2.pl16
1 files changed, 12 insertions, 4 deletions
diff --git a/challenge-146/james-smith/perl/ch-2.pl b/challenge-146/james-smith/perl/ch-2.pl
index 2348c8b946..d3f552e849 100644
--- a/challenge-146/james-smith/perl/ch-2.pl
+++ b/challenge-146/james-smith/perl/ch-2.pl
@@ -9,14 +9,22 @@ use Benchmark qw(cmpthese timethis);
use Data::Dumper qw(Dumper);
my @TESTS = (
- [ 0, 1 ],
+ [ 3,5, '3/5 3/2 1/2 1/1' ],
+ [ 4,3, '4/3 1/3 1/2 1/1' ],
+ [ 101,45, '101/45 56/45 11/45 11/34 11/23 11/12 11/1 10/1 9/1 8/1 7/1 6/1 5/1 4/1 3/1 2/1 1/1' ],
);
-is( my_function($_->[0]), $_->[1] ) foreach @TESTS;
+is( stringify( tree($_->[0],$_->[1]) ), $_->[2] ) foreach @TESTS;
done_testing();
-sub my_function {
- return 1;
+sub tree {
+ my $tree = [[ my($n,$d)=@_ ]];
+ push @{$tree}, [($n,$d)=$d>$n?($n,$d-$n):($n-$d,$d)] while $n>1||$d>1;
+ $tree;
+}
+
+sub stringify {
+ join ' ', map { "$_->[0]/$_->[1]" } @{$_[0]};
}