aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-137/e-choroba/perl/ch-1.pl29
-rwxr-xr-xchallenge-137/e-choroba/perl/ch-2.pl29
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-137/e-choroba/perl/ch-1.pl b/challenge-137/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..a758a4b02c
--- /dev/null
+++ b/challenge-137/e-choroba/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Time::Piece;
+
+sub long_year {
+ my ($from, $to) = @_;
+ my @long;
+ for my $year ($from .. $to) {
+ my $tp = 'Time::Piece'->strptime("$year-12-31", '%Y-%m-%d');
+ push @long, $year if $tp->week == 53;
+ }
+ return \@long
+}
+
+use Test2::V0;
+plan 1;
+
+is long_year(1900, 2100),
+ [1903, 1908, 1914, 1920, 1925,
+ 1931, 1936, 1942, 1948, 1953,
+ 1959, 1964, 1970, 1976, 1981,
+ 1987, 1992, 1998, 2004, 2009,
+ 2015, 2020, 2026, 2032, 2037,
+ 2043, 2048, 2054, 2060, 2065,
+ 2071, 2076, 2082, 2088, 2093,
+ 2099],
+ 'Example';
diff --git a/challenge-137/e-choroba/perl/ch-2.pl b/challenge-137/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..b8346f8073
--- /dev/null
+++ b/challenge-137/e-choroba/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+sub lychrel_number {
+ my ($n) = @_;
+ for (1 .. 500) {
+
+ $n += reverse $n;
+ return 0 if $n == reverse $n;
+
+ # Comment out to get the correct answer for 89.
+ # "use bigint;" to make it work for 196.
+ return 1 if $n >= 1e7;
+ }
+ return 1
+}
+
+use Test2::V0;
+plan 5;
+
+is lychrel_number(56), 0, 'Example 1';
+is lychrel_number(57), 0, 'Example 2';
+is lychrel_number(59), 0, 'Example 3';
+
+# Wrong answer as 17735476 >= 1e7.
+is lychrel_number(89), 1, '24 iterations';
+
+is lychrel_number(196), 1, 'Lychrel number';