From 8f3c7375c43ac785fb3e767ca76d6fb6aa5157a3 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 4 Aug 2021 11:56:32 +0200 Subject: Task 1 done right. --- challenge-124/luca-ferrari/raku/ch-1.p6 | 70 ++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/challenge-124/luca-ferrari/raku/ch-1.p6 b/challenge-124/luca-ferrari/raku/ch-1.p6 index 90904038c3..c0f70bdb64 100644 --- a/challenge-124/luca-ferrari/raku/ch-1.p6 +++ b/challenge-124/luca-ferrari/raku/ch-1.p6 @@ -1,27 +1,53 @@ #!raku +class Line { + has $.char = '^'; + has $.start = 0; + has $.end = 0; + has $.pad-with-blanks = True; + + method draw() { + my $line = ' ' x $!start ~ $!char; +# $line ~= $!start ~ "<>" ~ $!end; + if ( $!pad-with-blanks ) { + $line ~= ' ' x ( $!end - $!start - 1 ) ~ $!char; + } + else { + $line ~= $!char x ( $!end - $!start ); + } + + say $line; + + } +} + + sub MAIN() { - - my $venus = qq:to/EOF/; - ^^^^^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^ ^ - ^^^^^ - ^ - ^ - ^ - ^^^^^ - ^ - ^ -EOF - -$venus.say; + + my @lines; + my $size = 5; + my ( $start, $end ) = $size, $size * 2 - 1; + @lines.push: Line.new( start => $start, end => $end, pad-with-blanks => False ); + while ( $start > 0 ) { + @lines.push: Line.new( start => --$start, end => ++$end ); + } + + # add three lines + @lines.push: Line.new( start => 0, end => $end ) for 1 .. 3; + + # decreasing part + while ( $start < $size ) { + @lines.push: Line.new( start => ++$start, end => --$end ); + } + + # final line + @lines.push: Line.new( start => $start, end => $end, pad-with-blanks => False ); + + # add three lines with a single char + @lines.push: Line.new( start => $start + $size / 2, end => $start + $size / 2, pad-with-blanks => False ) for 1 .. 3; + @lines.push: Line.new( start => $start, end => $end, pad-with-blanks => False ); + @lines.push: Line.new( start => $start + $size / 2, end => $start + $size / 2, pad-with-blanks => False ) for 1 .. 3; + + .draw for @lines } -- cgit