aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon Proctor <simon.proctor@gmail.com>2021-08-02 10:35:01 +0100
committerScimon Proctor <simon.proctor@gmail.com>2021-08-02 10:35:01 +0100
commitc1646be90db79f876b0bafed002c3976333ee540 (patch)
tree6ec621c0e7a79284d4d3f1115ce7e0955dc5fc0b
parent07cf10cea7d97f529a19e00ea9a1f902fc74177e (diff)
downloadperlweeklychallenge-club-c1646be90db79f876b0bafed002c3976333ee540.tar.gz
perlweeklychallenge-club-c1646be90db79f876b0bafed002c3976333ee540.tar.bz2
perlweeklychallenge-club-c1646be90db79f876b0bafed002c3976333ee540.zip
Challege 1 (with variable sizing)
-rw-r--r--challenge-124/simon-proctor/raku/ch-1.raku47
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-124/simon-proctor/raku/ch-1.raku b/challenge-124/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..da4022e6b9
--- /dev/null
+++ b/challenge-124/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,47 @@
+#!/usr/bin/env raku
+
+constant SYM = '♀';
+
+multi sub MAIN( 1 ) is hidden-from-USAGE { say SYM }
+
+#| Given a radius for the circle draw the Female Symbol
+multi sub MAIN(
+ UInt $rad where * <= 20 #= Radius from 1 to 20
+) {
+ draw-circle( $rad );
+ draw-cross( $rad );
+}
+
+sub draw-circle( \rad ) {
+ # Totally nicked this from here : https://stackoverflow.com/questions/1022178/how-to-make-a-circle-on-a-grid
+ my \grid-size = (rad * 2)+1;
+ my @grid = [ [ " " xx grid-size ] xx grid-size ];
+ my Int $x = 0;
+ my Int $y = rad;
+ my Int $d = 3 - (2 * rad);
+ my \c = rad;
+ repeat {
+ @grid[c+$y][c+$x] = SYM;
+ @grid[c-$y][c+$x] = SYM;
+ @grid[c-$y][c-$x] = SYM;
+ @grid[c+$y][c-$x] = SYM;
+ @grid[c+$x][c+$y] = SYM;
+ @grid[c-$x][c+$y] = SYM;
+ @grid[c-$x][c-$y] = SYM;
+ @grid[c+$x][c-$y] = SYM;
+ if ( $d < 0 ) {
+ $d = $d + (4 * $x) + 6
+ } else {
+ $d = $d + 4 * ( $x - $y) + 10;
+ $y--;
+ }
+ $x++;
+ } while ($x <= $y);
+ .say for @grid.map( *.join("") );
+}
+
+sub draw-cross( \rad ) {
+ (" " x rad ~ SYM).say for 1..^rad;
+ (" " ~ (SYM x (rad*2)-1)).say;
+ (" " x rad ~ SYM).say for 1..^rad;
+}