diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2021-08-04 11:56:32 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2021-08-04 11:56:32 +0200 |
| commit | 8f3c7375c43ac785fb3e767ca76d6fb6aa5157a3 (patch) | |
| tree | ee1f9673ceed5270ecd2dad84b469b7ec7e9d4c6 | |
| parent | 4b48a7703b3bb8fbaa23d7b7a22763c755fd6847 (diff) | |
| download | perlweeklychallenge-club-8f3c7375c43ac785fb3e767ca76d6fb6aa5157a3.tar.gz perlweeklychallenge-club-8f3c7375c43ac785fb3e767ca76d6fb6aa5157a3.tar.bz2 perlweeklychallenge-club-8f3c7375c43ac785fb3e767ca76d6fb6aa5157a3.zip | |
Task 1 done right.
| -rw-r--r-- | challenge-124/luca-ferrari/raku/ch-1.p6 | 70 |
1 files 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 } |
