diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-06 20:23:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-06 20:23:33 +0000 |
| commit | bda07727a3192eb6c7fdb73c81d100a9fe7297d6 (patch) | |
| tree | 1fd970b49824a7ac50cea7c54b2323e2b7f6405b | |
| parent | f439b0895e991371b3fe24ec314b4e6d02a975a6 (diff) | |
| parent | 031a3a44299cbc422b9cd5bfc6f380fa8d77be26 (diff) | |
| download | perlweeklychallenge-club-bda07727a3192eb6c7fdb73c81d100a9fe7297d6.tar.gz perlweeklychallenge-club-bda07727a3192eb6c7fdb73c81d100a9fe7297d6.tar.bz2 perlweeklychallenge-club-bda07727a3192eb6c7fdb73c81d100a9fe7297d6.zip | |
Merge pull request #5168 from LubosKolouch/master
Challenge 137 LK Perl
| -rw-r--r-- | challenge-137/lubos-kolouch/perl/ch-1.pl | 33 | ||||
| -rw-r--r-- | challenge-137/lubos-kolouch/perl/ch-2.pl | 30 |
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; |
