aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-150/james-smith/perl/ch-1.pl15
-rw-r--r--challenge-150/james-smith/perl/ch-2.pl16
2 files changed, 15 insertions, 16 deletions
diff --git a/challenge-150/james-smith/perl/ch-1.pl b/challenge-150/james-smith/perl/ch-1.pl
index b7e5227c20..d9fe0bbdf5 100644
--- a/challenge-150/james-smith/perl/ch-1.pl
+++ b/challenge-150/james-smith/perl/ch-1.pl
@@ -12,16 +12,23 @@ my @TESTS = (
[ [1234,5678], 7 ],
[ [5678,1234], 3 ],
);
-is( fibnum(@{$_->[0]}), $_->[1] ) foreach @TESTS;
+is( fibnum( @{$_->[0]} ), $_->[1] ) foreach @TESTS;
+is( fibnum_nasty( @{$_->[0]} ), $_->[1] ) foreach @TESTS;
+is( fibnum_messy( @{$_->[0]} ), $_->[1] ) foreach @TESTS;
done_testing();
sub fibnum_messy {
- for( my($r,$s) = @_; 51>length $s || return substr $s,50,1;($r,$s) = ($s,$r.$s) ){}
+ ($a,$b)=@_;$b=$a.($a=$b)while 51>length$b;substr$b,50,1;
}
-sub fibnum {
+sub fibnum_nasty {
my ($r,$s) = @_;
- ($r,$s) = ($s,$r.$s) while 51>length $s;
+ $s=$r.($r=$s) while 51>length $s;
substr $s,50,1;
}
+sub fibnum {
+ my ( $r, $s ) = @_;
+ ( $r, $s ) = ( $s, $r.$s ) while 51 > length $s;
+ substr $s, 50, 1;
+}
diff --git a/challenge-150/james-smith/perl/ch-2.pl b/challenge-150/james-smith/perl/ch-2.pl
index 2348c8b946..a6af28ddcd 100644
--- a/challenge-150/james-smith/perl/ch-2.pl
+++ b/challenge-150/james-smith/perl/ch-2.pl
@@ -4,19 +4,11 @@ use strict;
use warnings;
use feature qw(say);
-use Test::More;
-use Benchmark qw(cmpthese timethis);
-use Data::Dumper qw(Dumper);
-my @TESTS = (
- [ 0, 1 ],
-);
+my($N,@p2) = (@ARGV?$ARGV[0]:500,4);
-is( my_function($_->[0]), $_->[1] ) foreach @TESTS;
-
-done_testing();
-
-sub my_function {
- return 1;
+for(my$c=3;$c*$c<$N;$c+=2){
+ ($_>$c)?((push@p2,$c*$c),last):$c*$c%$_||last for@p2;
}
+say for grep{my$t=$_;!grep{!($t%$_)}@p2}1..$N;