aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-003/nick-logan/perl5/ch-1.pl29
-rw-r--r--challenge-003/nick-logan/perl5/ch-2.pl13
-rw-r--r--challenge-003/nick-logan/perl6/ch-1.p629
-rw-r--r--challenge-003/nick-logan/perl6/ch-2.p613
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);
+}