diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-12-20 18:52:39 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-12-20 18:52:39 +0000 |
| commit | ee4acfd9c139e158146c2faf096f4f94f994869b (patch) | |
| tree | 2b3427d24103bbc5cfcfe397d55371292d57053e | |
| parent | 1aa8ecccec917bbdee515fef036e8f84c47dae22 (diff) | |
| download | perlweeklychallenge-club-ee4acfd9c139e158146c2faf096f4f94f994869b.tar.gz perlweeklychallenge-club-ee4acfd9c139e158146c2faf096f4f94f994869b.tar.bz2 perlweeklychallenge-club-ee4acfd9c139e158146c2faf096f4f94f994869b.zip | |
first pass
| -rw-r--r-- | challenge-144/james-smith/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-144/james-smith/perl/ch-2.pl | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-144/james-smith/perl/ch-1.pl b/challenge-144/james-smith/perl/ch-1.pl new file mode 100644 index 0000000000..97fe5b4e33 --- /dev/null +++ b/challenge-144/james-smith/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); + + +my $N = 1000; +my @primes = (2); +my @semi_primes = (4); + +foreach my $p ( map { 1+2*$_ } 1..($N/4) ) { + map { ($p%$_)||(next) } @primes; + push @primes,$p; + push @semi_primes,grep {$_<=$N} map{$p*$_} @primes; +} + +say for sort {$a<=>$b} @semi_primes; + diff --git a/challenge-144/james-smith/perl/ch-2.pl b/challenge-144/james-smith/perl/ch-2.pl new file mode 100644 index 0000000000..024a36197b --- /dev/null +++ b/challenge-144/james-smith/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); + +my (@seq,%seq_hash); + +say "@{[ ulam(1,2,100) ]}"; +say "@{[ ulam(2,3,100) ]}"; +say "@{[ ulam(2,5,100) ]}"; + +sub ulam { + my%seq_hash=map{$_,$_}my@seq=($_[0],my$n=$_[1]); + for(;scalar @seq<$_[2];++$n){ + push@seq,$seq_hash{$n}=$n if 1==grep{2*$_<$n&&$seq_hash{$n-$_}}@seq; + } + @seq; +} + |
