aboutsummaryrefslogtreecommitdiff
path: root/challenge-137
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-08 00:24:22 +0000
committerGitHub <noreply@github.com>2021-11-08 00:24:22 +0000
commit920a79895fc318a41b44d1b2a865e9be49b6d72b (patch)
treed077538b766ff4c93af5aab985b500519394db0a /challenge-137
parentbdaee6cca40cfd4d1565a748b467159196fd2431 (diff)
parentb7f5f2199f8537be23dabd09459f98914e436c5c (diff)
downloadperlweeklychallenge-club-920a79895fc318a41b44d1b2a865e9be49b6d72b.tar.gz
perlweeklychallenge-club-920a79895fc318a41b44d1b2a865e9be49b6d72b.tar.bz2
perlweeklychallenge-club-920a79895fc318a41b44d1b2a865e9be49b6d72b.zip
Merge pull request #5177 from Util/branch-for-challenge-137
Add Raku and Perl solutions for #137 by Bruce Gray
Diffstat (limited to 'challenge-137')
-rw-r--r--challenge-137/bruce-gray/raku/ch-1.raku18
-rw-r--r--challenge-137/bruce-gray/raku/ch-2.raku28
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-137/bruce-gray/raku/ch-1.raku b/challenge-137/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..7acbafd81f
--- /dev/null
+++ b/challenge-137/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,18 @@
+sub is-long ( Int $year --> Bool ) {
+ return Date.new("$year-12-31").week-number == 53;
+}
+
+use Test; plan 1;
+my @expected =
+ 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
+;
+
+my @got = grep &is-long, 1900 .. 2100;
+is-deeply @got, @expected;
diff --git a/challenge-137/bruce-gray/raku/ch-2.raku b/challenge-137/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..2137e879f1
--- /dev/null
+++ b/challenge-137/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,28 @@
+sub is-Lychrel-number ( Int $n is copy --> Bool ) {
+ my $iterations;
+ loop {
+ $n += $n.flip;
+
+ return False if $n eq $n.flip;
+ return True if $n >= 10_000_000
+ or $iterations++ > 500;
+ }
+}
+
+use Test;
+my @tests =
+ # From the task description:
+ 56 => False,
+ 57 => False,
+ 59 => False,
+
+ # Added:
+ 464 => True, # Should be False, but not shown to be False inside the 10_000_000 limit, so True.
+ 196 => True, # Famously huge
+;
+plan +@tests;
+
+for @tests -> ( :key($input), :value($expected) ) {
+ is is-Lychrel-number($input), $expected,
+ "is-Lychrel-number {$input.fmt('%3d')} == $expected";
+}