From 52a7ca4f612c774a2f87cab8d145b683f53c26ca Mon Sep 17 00:00:00 2001 From: Scimon Proctor Date: Mon, 19 Jul 2021 09:36:05 +0100 Subject: Challenge 1 --- challenge-122/simon-proctor/raku/ch-1.raku | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-122/simon-proctor/raku/ch-1.raku diff --git a/challenge-122/simon-proctor/raku/ch-1.raku b/challenge-122/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..5c685c3dd0 --- /dev/null +++ b/challenge-122/simon-proctor/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub avg($avg,$val) { + state $count = 1; + my $sum = $avg*$count; + $sum += $val; + $count++; + $sum / $count; +} + +#| Given a list of numbers print the average of the list with each point in the list +multi sub MAIN( *@N ) { + ( [\[&avg]] @N ).join(", ").say; +} + +#| Read from STDIN and output the running average after each number +multi sub MAIN() { + .say for [\[&avg]] $*IN.lines; +} -- cgit From ecb612591c012ba4de6480192e0e049ec8d17f00 Mon Sep 17 00:00:00 2001 From: Scimon Proctor Date: Mon, 19 Jul 2021 09:56:06 +0100 Subject: Challenge 2 --- challenge-122/simon-proctor/raku/ch-2.raku | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 challenge-122/simon-proctor/raku/ch-2.raku diff --git a/challenge-122/simon-proctor/raku/ch-2.raku b/challenge-122/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..1c10942d42 --- /dev/null +++ b/challenge-122/simon-proctor/raku/ch-2.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku + +#| Given a number print all the possible ways to score that in basketball +sub MAIN (Int() $N) { + .say for (|(1 xx $N), |(2 xx $N), |(3 xx $N)) + .combinations(1..$N) + .unique(:with(&[eqv])) + .grep( -> @l { ([+] @l) ~~ $N } ) + .map( -> @l { @l.permutations.unique(:with(&[eqv])).Slip } ) + .map( *.join(",") ) +} -- cgit From f0355014578390a127272346354f339b3d2a68d0 Mon Sep 17 00:00:00 2001 From: Scimon Proctor Date: Mon, 19 Jul 2021 09:59:47 +0100 Subject: Remove uneeded duplication --- challenge-122/simon-proctor/raku/ch-2.raku | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-122/simon-proctor/raku/ch-2.raku b/challenge-122/simon-proctor/raku/ch-2.raku index 1c10942d42..8487b83a62 100644 --- a/challenge-122/simon-proctor/raku/ch-2.raku +++ b/challenge-122/simon-proctor/raku/ch-2.raku @@ -2,7 +2,7 @@ #| Given a number print all the possible ways to score that in basketball sub MAIN (Int() $N) { - .say for (|(1 xx $N), |(2 xx $N), |(3 xx $N)) + .say for (|(1 xx $N), |(2 xx ($N div 2)), |(3 xx ($N div 3))) .combinations(1..$N) .unique(:with(&[eqv])) .grep( -> @l { ([+] @l) ~~ $N } ) -- cgit