From 6058b52198f35728c85bfcaa463d68312606c5ac Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 25 Jan 2021 11:18:47 +0000 Subject: Ceaser Cypher --- challenge-097/simon-proctor/raku/ch-1.raku | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-097/simon-proctor/raku/ch-1.raku diff --git a/challenge-097/simon-proctor/raku/ch-1.raku b/challenge-097/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..c0436002bc --- /dev/null +++ b/challenge-097/simon-proctor/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +use v6; + +#| Given a shift amount (integer can be negative) and a list of string encode using the Ceaser Cypher +sub MAIN( + Int() $shift is copy, #= Amount to shift the letters by + *@words where @words.grep({ ! m!^ <[A..Z]>+ $! }).elems == 0 #= Words, all uppercase +) { + my @alpha = ("A".."Z").Array; + if ( $shift < 0 ) { $shift = 26+$shift } + my @shifted = [ |@alpha[(26-$shift)..25], |@alpha[0..(25-$shift)] ]; + + say @words.map( { $_.trans( @alpha.join => @shifted.join ) } ).join(" "); +} -- cgit