From b68edfed700bb9ea073f1d7b514dee22c3bf3b28 Mon Sep 17 00:00:00 2001 From: Util Date: Sun, 6 Mar 2022 00:16:38 -0600 Subject: Add TWC 154 solutions by Bruce Gray : Raku, Perl, and Python. --- challenge-154/bruce-gray/perl/ch-1.pl | 16 ++++++++++++++++ challenge-154/bruce-gray/perl/ch-2.pl | 13 +++++++++++++ challenge-154/bruce-gray/python/ch-1.py | 9 +++++++++ challenge-154/bruce-gray/python/ch-2.py | 25 +++++++++++++++++++++++++ challenge-154/bruce-gray/raku/ch-1.raku | 9 +++++++++ challenge-154/bruce-gray/raku/ch-2.raku | 3 +++ 6 files changed, 75 insertions(+) create mode 100755 challenge-154/bruce-gray/perl/ch-1.pl create mode 100644 challenge-154/bruce-gray/perl/ch-2.pl create mode 100644 challenge-154/bruce-gray/python/ch-1.py create mode 100644 challenge-154/bruce-gray/python/ch-2.py create mode 100644 challenge-154/bruce-gray/raku/ch-1.raku create mode 100644 challenge-154/bruce-gray/raku/ch-2.raku 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; +use List::Lazy qw; +use ntheory qw; + +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); -- cgit