From 031a3a44299cbc422b9cd5bfc6f380fa8d77be26 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sat, 6 Nov 2021 14:39:27 +0100 Subject: Challenge 137 LK Perl --- challenge-137/lubos-kolouch/perl/ch-1.pl | 33 ++++++++++++++++++++++++++++++++ challenge-137/lubos-kolouch/perl/ch-2.pl | 30 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 challenge-137/lubos-kolouch/perl/ch-1.pl create mode 100644 challenge-137/lubos-kolouch/perl/ch-2.pl 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; -- cgit