diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-06-20 13:26:06 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-06-20 13:26:06 +0100 |
| commit | 414d13aa64234592c387ada15a4a9573b1153f12 (patch) | |
| tree | 56d4964cb3dd144724d12444f99b881e1ccc18f8 /challenge-170/james-smith | |
| parent | 7163d586d6d8bc8dc3747ee295baaa4948447c6e (diff) | |
| download | perlweeklychallenge-club-414d13aa64234592c387ada15a4a9573b1153f12.tar.gz perlweeklychallenge-club-414d13aa64234592c387ada15a4a9573b1153f12.tar.bz2 perlweeklychallenge-club-414d13aa64234592c387ada15a4a9573b1153f12.zip | |
added in short version of ch-1.pl
Diffstat (limited to 'challenge-170/james-smith')
| -rw-r--r-- | challenge-170/james-smith/README.md | 10 | ||||
| -rw-r--r-- | challenge-170/james-smith/perl/ch-1.pl | 7 |
2 files changed, 16 insertions, 1 deletions
diff --git a/challenge-170/james-smith/README.md b/challenge-170/james-smith/README.md index b07dc7b7c9..72ed1b2578 100644 --- a/challenge-170/james-smith/README.md +++ b/challenge-170/james-smith/README.md @@ -35,6 +35,16 @@ say sprintf '%'.int(2+4/3*log($x[-1])/log 10).'s', th($_) for @x; sub th { scalar reverse( (reverse $_[0]) =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/gr ) } ``` +### Short version.... + +A short version of this - we remove the flexibility of using the parameters (`N=10`) and instead of working out he 9th prime in code replacing it with 23, gives, the 30 byte code.. + +```perl +say$a=1;forprimes{say$a*=$_}nth_prime($ARGV[0]//10)-1 # 53 bytes +say$a=1;forprimes{say$a*=$_}nth_prime 9 # 39 bytes +say$a=1;forprimes{say$a*=$_}23 # 30 bytes +``` + # Challenge 2 - Kronecker Product ***Write a script to implement Kronecker Product on the given 2 matrices. e.g.*** diff --git a/challenge-170/james-smith/perl/ch-1.pl b/challenge-170/james-smith/perl/ch-1.pl index c1592956e2..9109ba2161 100644 --- a/challenge-170/james-smith/perl/ch-1.pl +++ b/challenge-170/james-smith/perl/ch-1.pl @@ -10,9 +10,14 @@ use Math::Prime::Util qw(nth_prime forprimes); use Data::Dumper qw(Dumper); use bignum; -my @x = (1); forprimes { push @x, $x[-1] * $_ } nth_prime ($ARGV[0]//10); +my @x = (1); forprimes { push @x, $x[-1] * $_ } nth_prime($ARGV[0]//10)-1; say sprintf '%'.int(2+4/3*log($x[-1])/log 10).'s', th($_) for @x; sub th { scalar reverse( (reverse $_[0]) =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/gr ) } + +#----|----#----|----#----|----#----|----#----|----#----|---- +say$a=1;forprimes{say$a*=$_}nth_prime($ARGV[0]//10)-1; +say$a=1;forprimes{say$a*=$_}nth_prime 9; +say$a=1;forprimes{say$a*=$_}23 |
