From 8300307effaa6503bd3abb6988a5550f0d064057 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 30 Nov 2020 10:47:09 +0000 Subject: Challenges done --- challenge-089/simon-proctor/raku/ch-1.raku | 8 ++++++++ challenge-089/simon-proctor/raku/ch-2.raku | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 challenge-089/simon-proctor/raku/ch-1.raku create mode 100644 challenge-089/simon-proctor/raku/ch-2.raku diff --git a/challenge-089/simon-proctor/raku/ch-1.raku b/challenge-089/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..3a76f49ad6 --- /dev/null +++ b/challenge-089/simon-proctor/raku/ch-1.raku @@ -0,0 +1,8 @@ +#!/usr/bin/env raku + +use v6; + +#| Given a number $N print the sum off all the GCD's of all the combinations of 1..$N +sub MAIN ( UInt $N ) { + say [+] (1..$N).combinations(2).map( -> ( $a, $b ) { $a gcd $b } ) +} diff --git a/challenge-089/simon-proctor/raku/ch-2.raku b/challenge-089/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..a6615fbee6 --- /dev/null +++ b/challenge-089/simon-proctor/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +use v6; + +my @rows = ( (0,1,2),(3,4,5),(6,7,8), + (0,3,6),(1,4,7),(2,3,8), + (0,4,8),(2,4,6) ); + +#| Print a 3x3 grid of the number 1-9 where each horizontal, vertical and diagonal adds up to 15 +sub MAIN( Bool :a(:$all) = False ) { + for (1..9).permutations().race().grep( -> @grid { [==] ( 15, |@grid[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]].map( -> @a { [+] @a } ) ) } ) -> @grid { + say @grid.rotor(3).map( *.join( " " ) ).join("\n"); + exit unless $all; + say '---'; + } +} -- cgit