From ae71ff22a71c3718321f708b656dc9b6730e42f6 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Tue, 21 Jul 2020 09:16:47 +0100 Subject: Week 70 Challenge 1 and late submission for lest week --- challenge-069/simon-proctor/raku/ch-2.raku | 15 +++++++++++++++ challenge-070/simon-proctor/raku/ch-1.raku | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 challenge-069/simon-proctor/raku/ch-2.raku create mode 100644 challenge-070/simon-proctor/raku/ch-1.raku diff --git a/challenge-069/simon-proctor/raku/ch-2.raku b/challenge-069/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..1023bf20c8 --- /dev/null +++ b/challenge-069/simon-proctor/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +#| Calculate S1000 where see https://perlweeklychallenge.org/blog/perl-weekly-challenge-069/ +multi sub MAIN ( UInt $S = 30 ) { + my @ret = []; + my $count = 0; + while $S > $count { + @ret .= push( "0", @ret.hyper.reverse.map(*.trans(<0 1> => <1 0>)).Slip ); + $count++; + } + say @ret.join(""); +} + + + diff --git a/challenge-070/simon-proctor/raku/ch-1.raku b/challenge-070/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..4ce551bfc6 --- /dev/null +++ b/challenge-070/simon-proctor/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +use v6 + +#| Given a string, swap count and offset swap characters in the string +sub MAIN ( + Str $S, #= String to manipulate + UInt $C, #= Swap count + UInt $O where { $C <= $O && $C + $O <= $S.codes }, #= Offset +) { + my @swaps = $S.comb; + my $N = $S.codes; + for 1..$C -> $i { + my $x = $i % $N; + my $y = ($i+$O) % $N; + @swaps[$x,$y] = @swaps[$y,$x]; + } + + @swaps.join("").say; +} -- cgit