diff options
| author | Nick Logan <nlogan@gmail.com> | 2019-04-10 23:12:19 -0400 |
|---|---|---|
| committer | Nick Logan <nlogan@gmail.com> | 2019-04-10 23:22:58 -0400 |
| commit | 08421ab29ca411cc43513682868aebb4dde67fc4 (patch) | |
| tree | 4b324c3702007fce423b971524a8e05b78a4438f | |
| parent | 481aefbea598626938020fae30ee74ad91339bda (diff) | |
| download | perlweeklychallenge-club-08421ab29ca411cc43513682868aebb4dde67fc4.tar.gz perlweeklychallenge-club-08421ab29ca411cc43513682868aebb4dde67fc4.tar.bz2 perlweeklychallenge-club-08421ab29ca411cc43513682868aebb4dde67fc4.zip | |
Add week 3 polyglot solutions
| -rw-r--r-- | challenge-003/nick-logan/perl5/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-003/nick-logan/perl5/ch-2.pl | 13 | ||||
| -rw-r--r-- | challenge-003/nick-logan/perl6/ch-1.p6 | 29 | ||||
| -rw-r--r-- | challenge-003/nick-logan/perl6/ch-2.p6 | 13 |
4 files changed, 84 insertions, 0 deletions
diff --git a/challenge-003/nick-logan/perl5/ch-1.pl b/challenge-003/nick-logan/perl5/ch-1.pl new file mode 100644 index 0000000000..b76f7d6d92 --- /dev/null +++ b/challenge-003/nick-logan/perl5/ch-1.pl @@ -0,0 +1,29 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my $numbers_tried = 0; +my $numbers_found = 0; + +NUMBERS: while ($numbers_found != @ARGV[0]) { + + $numbers_tried++; + my $state = $numbers_tried; + while ($state != 1) { + if ($state % 2 == 0) { + $state /= 2; + } + elsif ($state % 3 == 0) { + $state /= 3; + } + elsif ($state % 5 == 0) { + $state /= 5; + } + else { + next NUMBERS; + } + } + $numbers_found++; + + print("$numbers_tried\n"); +} diff --git a/challenge-003/nick-logan/perl5/ch-2.pl b/challenge-003/nick-logan/perl5/ch-2.pl new file mode 100644 index 0000000000..10bcd74535 --- /dev/null +++ b/challenge-003/nick-logan/perl5/ch-2.pl @@ -0,0 +1,13 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my @state = (1,); +for (1 .. @ARGV[0]) { + print(join(" ", @state), "\n"); + my @row = map &{ sub ($_) { @state[$_] + (@state[$_ + 1] // 0) } }.(), (0 .. ($_ - 2)); + @state = (); + push(@state, 1); + push(@state, $_) for @row; + push(@state, 1); +} diff --git a/challenge-003/nick-logan/perl6/ch-1.p6 b/challenge-003/nick-logan/perl6/ch-1.p6 new file mode 100644 index 0000000000..b76f7d6d92 --- /dev/null +++ b/challenge-003/nick-logan/perl6/ch-1.p6 @@ -0,0 +1,29 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my $numbers_tried = 0; +my $numbers_found = 0; + +NUMBERS: while ($numbers_found != @ARGV[0]) { + + $numbers_tried++; + my $state = $numbers_tried; + while ($state != 1) { + if ($state % 2 == 0) { + $state /= 2; + } + elsif ($state % 3 == 0) { + $state /= 3; + } + elsif ($state % 5 == 0) { + $state /= 5; + } + else { + next NUMBERS; + } + } + $numbers_found++; + + print("$numbers_tried\n"); +} diff --git a/challenge-003/nick-logan/perl6/ch-2.p6 b/challenge-003/nick-logan/perl6/ch-2.p6 new file mode 100644 index 0000000000..10bcd74535 --- /dev/null +++ b/challenge-003/nick-logan/perl6/ch-2.p6 @@ -0,0 +1,13 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my @state = (1,); +for (1 .. @ARGV[0]) { + print(join(" ", @state), "\n"); + my @row = map &{ sub ($_) { @state[$_] + (@state[$_ + 1] // 0) } }.(), (0 .. ($_ - 2)); + @state = (); + push(@state, 1); + push(@state, $_) for @row; + push(@state, 1); +} |
