aboutsummaryrefslogtreecommitdiff
path: root/challenge-137
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2021-11-06 14:39:27 +0100
committerLubos Kolouch <lubos@kolouch.net>2021-11-06 14:39:27 +0100
commit031a3a44299cbc422b9cd5bfc6f380fa8d77be26 (patch)
tree5eaa57c88b47c788090db073fc395c62c478d8ab /challenge-137
parentea1f2d69a93d7d767bfdd4e2b6be835f3a8e0946 (diff)
downloadperlweeklychallenge-club-031a3a44299cbc422b9cd5bfc6f380fa8d77be26.tar.gz
perlweeklychallenge-club-031a3a44299cbc422b9cd5bfc6f380fa8d77be26.tar.bz2
perlweeklychallenge-club-031a3a44299cbc422b9cd5bfc6f380fa8d77be26.zip
Challenge 137 LK Perl
Diffstat (limited to 'challenge-137')
-rw-r--r--challenge-137/lubos-kolouch/perl/ch-1.pl33
-rw-r--r--challenge-137/lubos-kolouch/perl/ch-2.pl30
2 files changed, 63 insertions, 0 deletions
diff --git a/challenge-137/lubos-kolouch/perl/ch-1.pl b/challenge-137/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..ed4f70aed3
--- /dev/null
+++ b/challenge-137/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+use DateTime;
+
+sub get_long_years {
+ # Get years with 53 weeks between 1900 and 2100
+
+ my @result;
+
+ for (1900..2100) {
+ my $dt = DateTime->new(
+ year => $_,
+ month => 12,
+ day => 31);
+
+ push @result, $_ if $dt->week_number == 53;
+ }
+
+ return \@result;
+}
+
+use Test::More;
+
+is_deeply(get_long_years(), [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]);
+
+done_testing;
diff --git a/challenge-137/lubos-kolouch/perl/ch-2.pl b/challenge-137/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..e949a112df
--- /dev/null
+++ b/challenge-137/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+sub is_lychrel_number {
+ my $what = shift;
+
+ my $iter_count = 0;
+
+ while ($iter_count < 500) {
+ $iter_count++;
+
+ $what += reverse $what;
+
+ last if $what >= 10_000_000;
+
+ return 0 if $what == reverse $what;
+
+ }
+
+ return 1;
+}
+
+use Test::More;
+
+is(is_lychrel_number(56), 0);
+is(is_lychrel_number(57), 0);
+is(is_lychrel_number(59), 0);
+is(is_lychrel_number(10911), 1);
+
+done_testing;