aboutsummaryrefslogtreecommitdiff
path: root/challenge-036
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-12-01 23:52:16 +0000
committerGitHub <noreply@github.com>2019-12-01 23:52:16 +0000
commitcb017c5afc2dba4fdd9714b25d8a01bc31f26f21 (patch)
treefa1d6762e5a3a1a756bed68dd84f48d1a343275a /challenge-036
parent030457302cc1bf86fc8e3055ded1a39c75cb4b7a (diff)
parenta6d142e827d037da73ea229ee5682b2b4e9d8e96 (diff)
downloadperlweeklychallenge-club-cb017c5afc2dba4fdd9714b25d8a01bc31f26f21.tar.gz
perlweeklychallenge-club-cb017c5afc2dba4fdd9714b25d8a01bc31f26f21.tar.bz2
perlweeklychallenge-club-cb017c5afc2dba4fdd9714b25d8a01bc31f26f21.zip
Merge pull request #988 from mienaikage/036-raku
Solutions for challenge-036 in Raku
Diffstat (limited to 'challenge-036')
-rwxr-xr-xchallenge-036/daniel-mita/perl6/ch-1.p614
-rwxr-xr-xchallenge-036/daniel-mita/perl6/ch-2.p616
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-036/daniel-mita/perl6/ch-1.p6 b/challenge-036/daniel-mita/perl6/ch-1.p6
new file mode 100755
index 0000000000..a4452b67b8
--- /dev/null
+++ b/challenge-036/daniel-mita/perl6/ch-1.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl6
+
+grammar VIN {
+ token TOP { <WMI> <VDS> <VIS> }
+ token WMI { <.char> ** 3 }
+ token VDS { <.char> ** 6 }
+ token VIS { <.char> ** 7 }
+ token char { <[A..H J..N P R..Z 0..9]> }
+}
+
+sub MAIN (
+ Str $VIN, #= 17 character Vehicle Identification Number
+ --> Nil
+) { VIN.parse($VIN).say }
diff --git a/challenge-036/daniel-mita/perl6/ch-2.p6 b/challenge-036/daniel-mita/perl6/ch-2.p6
new file mode 100755
index 0000000000..bcd74021c4
--- /dev/null
+++ b/challenge-036/daniel-mita/perl6/ch-2.p6
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl6
+# I was hoping to attempt some other approaches to this challenge,
+# but sadly find myself short on time so just brute-forcing it.
+
+# Create 5 boxes with random weights and amounts
+my @boxes = <R B G Y P>.map({ $_ => %( :weight((1..10).roll), :amount((1..100).roll) ) });
+
+.say for |@boxes, '';
+
+.Hash.keys.say for @boxes
+ # Generate all possible combinations of boxes
+ .combinations(1 .. ∞)
+ # Grep the ones with valid weights
+ .grep(*.map(*.value<weight>).sum ≤ 15)
+ # Sort them by total value
+ .sort({ $_($^b) <=> $_($^a) given *.map(*.value<amount>).sum });