From 72b11ec48a23e1ac5da44c6f65ecd56af4fb5089 Mon Sep 17 00:00:00 2001 From: Scimon Date: Mon, 11 Apr 2022 16:14:43 +0100 Subject: Challenge 1 and 2 --- challenge-160/simon-proctor/raku/ch-1.raku | 16 ++++++++++++++++ challenge-160/simon-proctor/raku/ch-2.raku | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 challenge-160/simon-proctor/raku/ch-1.raku create mode 100644 challenge-160/simon-proctor/raku/ch-2.raku diff --git a/challenge-160/simon-proctor/raku/ch-1.raku b/challenge-160/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..e01042edf1 --- /dev/null +++ b/challenge-160/simon-proctor/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +#| Given an integer between 1 and 9 print the four is magic chain for it +sub MAIN( + Int() $a is copy where 0 < * < 10 #= Integer between 1 and 9 +) { + my @n=<>; + my @o; + while ( $a != 4 ) { + my $l = @n[$a].codes; + @o.push("{@n[$a]} is {@n[$l]}"); + $a=$l; + } + @o.push("four is magic."); + @o.join(", ").tc.say +} diff --git a/challenge-160/simon-proctor/raku/ch-2.raku b/challenge-160/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..fb71aeeec1 --- /dev/null +++ b/challenge-160/simon-proctor/raku/ch-2.raku @@ -0,0 +1,13 @@ +#!/usr/bin/env raku + +#| Given a list of numbers print any equilibrium indicies. Print -1 if there are none +sub MAIN( *@a ) { + my $out = -1; + my $e = @a.end; for ( 0..$e ) -> $i { + if ( ([+] @a[^$i]) ~~ ([+] @a[$i^..$e]) ) { + say $i; + $out = ''; + } + } + say $out if $out; +} -- cgit