diff options
| author | Util <bruce.gray@acm.org> | 2022-03-06 00:16:38 -0600 |
|---|---|---|
| committer | Util <bruce.gray@acm.org> | 2022-03-06 00:16:38 -0600 |
| commit | b68edfed700bb9ea073f1d7b514dee22c3bf3b28 (patch) | |
| tree | 7e86d694294588a321a4a67154bebf7a715d9d68 | |
| parent | b45785bb469b127b9ab48e53b1efe2d435cfc193 (diff) | |
| download | perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.tar.gz perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.tar.bz2 perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.zip | |
Add TWC 154 solutions by Bruce Gray : Raku, Perl, and Python.
| -rwxr-xr-x | challenge-154/bruce-gray/perl/ch-1.pl | 16 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/perl/ch-2.pl | 13 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/python/ch-1.py | 9 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/python/ch-2.py | 25 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/raku/ch-1.raku | 9 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/raku/ch-2.raku | 3 |
6 files changed, 75 insertions, 0 deletions
diff --git a/challenge-154/bruce-gray/perl/ch-1.pl b/challenge-154/bruce-gray/perl/ch-1.pl new file mode 100755 index 0000000000..d6870ab3f9 --- /dev/null +++ b/challenge-154/bruce-gray/perl/ch-1.pl @@ -0,0 +1,16 @@ +use Modern::Perl; +use List::Permutor; + +my @in = qw< + PELR PREL PERL PRLE PLER PLRE EPRL EPLR ERPL + ERLP ELPR ELRP RPEL RPLE REPL RELP RLPE RLEP + LPER LPRE LEPR LRPE LREP +>; +my %in_set = map { $_ => 1 } @in; + +my $permutor = List::Permutor->new( split '', $in[0] ); + +while ( my @letters = $permutor->next() ) { + my $word = join '', @letters; + say $word if not $in_set{$word}; +} diff --git a/challenge-154/bruce-gray/perl/ch-2.pl b/challenge-154/bruce-gray/perl/ch-2.pl new file mode 100644 index 0000000000..1e8abb7e99 --- /dev/null +++ b/challenge-154/bruce-gray/perl/ch-2.pl @@ -0,0 +1,13 @@ +use Modern::Perl; +use List::Util qw<uniq head>; +use List::Lazy qw<lazy_list>; +use ntheory qw<is_prime>; + +my $Padovan = lazy_list { + push @$_, $_->[-2] + $_->[-3]; + shift @$_; +} [1, 1, 1]; + +my $prime_pad = $Padovan->grep( sub { is_prime($_) } ); + +say join ', ', uniq $prime_pad->next(11); diff --git a/challenge-154/bruce-gray/python/ch-1.py b/challenge-154/bruce-gray/python/ch-1.py new file mode 100644 index 0000000000..141148a05b --- /dev/null +++ b/challenge-154/bruce-gray/python/ch-1.py @@ -0,0 +1,9 @@ +from itertools import permutations + +input_words = "PELR PREL PERL PRLE PLER PLRE EPRL EPLR ERPL ERLP ELPR ELRP RPEL RPLE REPL RELP RLPE RLEP LPER LPRE LEPR LRPE LREP".split() +input_set = set(input_words) + +for i in permutations(list(input_words[0])): + s = "".join(i) + if s not in input_set: + print(s) diff --git a/challenge-154/bruce-gray/python/ch-2.py b/challenge-154/bruce-gray/python/ch-2.py new file mode 100644 index 0000000000..aef20b2f69 --- /dev/null +++ b/challenge-154/bruce-gray/python/ch-2.py @@ -0,0 +1,25 @@ +from sympy import isprime +from itertools import islice + + +def Padovan(): + p = [1, 1, 1] + + while True: + p.append(p[-2] + p[-3]) + yield p.pop(0) + + +def squish(a): + last = None + for i in a: + if i != last: + yield i + last = i + + +def head(n, iterable): + return list(islice(iterable, n)) + + +print(head(10, squish(filter(isprime, Padovan())))) diff --git a/challenge-154/bruce-gray/raku/ch-1.raku b/challenge-154/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..1bfb38e816 --- /dev/null +++ b/challenge-154/bruce-gray/raku/ch-1.raku @@ -0,0 +1,9 @@ +my @in = < + PELR PREL PERL PRLE PLER PLRE EPRL EPLR ERPL + ERLP ELPR ELRP RPEL RPLE REPL RELP RLPE RLEP + LPER LPRE LEPR LRPE LREP +>; + +my @all = @in[0].comb.permutations».join; + +say .key for @all (-) @in; diff --git a/challenge-154/bruce-gray/raku/ch-2.raku b/challenge-154/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..7899baf632 --- /dev/null +++ b/challenge-154/bruce-gray/raku/ch-2.raku @@ -0,0 +1,3 @@ +constant @Padovan = 1, 1, 1, { sink $^c; $^a + $^b } ... *; + +say @Padovan.grep(&is-prime).squish.head(10); |
