aboutsummaryrefslogtreecommitdiff
path: root/challenge-117
diff options
context:
space:
mode:
authorAaron Smith <aaronreidsmith@gmail.com>2021-06-20 13:29:14 -0500
committerAaron Smith <aaronreidsmith@gmail.com>2021-06-20 13:30:02 -0500
commit8a67189fbe64dd2608fd38e5e89f4dae9bee4db1 (patch)
tree9a3a1c8d00f24b69f3459dd070a976676217d4b8 /challenge-117
parent255cff712c7fae9d2d5857255d2be789d77ea99c (diff)
downloadperlweeklychallenge-club-8a67189fbe64dd2608fd38e5e89f4dae9bee4db1.tar.gz
perlweeklychallenge-club-8a67189fbe64dd2608fd38e5e89f4dae9bee4db1.tar.bz2
perlweeklychallenge-club-8a67189fbe64dd2608fd38e5e89f4dae9bee4db1.zip
Challenge 117 (Part 1) - Raku
Diffstat (limited to 'challenge-117')
-rw-r--r--challenge-117/aaronreidsmith/raku/ch-1.raku34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-117/aaronreidsmith/raku/ch-1.raku b/challenge-117/aaronreidsmith/raku/ch-1.raku
new file mode 100644
index 0000000000..cd6f090815
--- /dev/null
+++ b/challenge-117/aaronreidsmith/raku/ch-1.raku
@@ -0,0 +1,34 @@
+#!/usr/bin/env raku
+
+use Lingua::EN::Numbers;
+
+sub challenge(Str $file) returns Str {
+ my $nums = $file.IO.lines.map(*.split(',').head.Int).List;
+ my $sum = $nums.sum;
+ my $expected = (1..$nums.elems + 1).sum;
+ my $missing = $expected - $sum;
+ "$missing, Line {cardinal($missing)}";
+}
+
+multi sub MAIN(Str $file) {
+ say challenge($file);
+}
+
+multi sub MAIN(Bool :$test) {
+ use Test;
+
+ for (1, 12, 15) -> $missing {
+ my $test-file = 'test.txt';
+
+ my @range = 1..15;
+ my @randomized = @range.pick(@range).grep(* != $missing);
+
+ for @randomized -> $i {
+ $test-file.IO.spurt("$i, Line {cardinal($i)}\n", :append);
+ }
+
+ is(challenge($test-file), "$missing, Line {cardinal($missing)}");
+
+ $test-file.IO.unlink
+ }
+}