diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-14 10:05:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-14 10:05:26 +0100 |
| commit | a7a06f3fee8a947b30b1127ba07f7b093d453fc0 (patch) | |
| tree | 785382b9024e56b182b1f101595faab8850a7789 | |
| parent | 3d100949d30f028a6bc3f7b04b8754d26d690f32 (diff) | |
| parent | 39157f79c1abfdd5fcf4c0ef96e2d23831595e48 (diff) | |
| download | perlweeklychallenge-club-a7a06f3fee8a947b30b1127ba07f7b093d453fc0.tar.gz perlweeklychallenge-club-a7a06f3fee8a947b30b1127ba07f7b093d453fc0.tar.bz2 perlweeklychallenge-club-a7a06f3fee8a947b30b1127ba07f7b093d453fc0.zip | |
Merge pull request #49 from fjwhittle/master
Fix typo in output, add optional timing output.
| -rw-r--r-- | challenge-003/fjwhittle/perl6/ch-1.p6 | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/challenge-003/fjwhittle/perl6/ch-1.p6 b/challenge-003/fjwhittle/perl6/ch-1.p6 index 0232dfceba..9d452f8b4a 100644 --- a/challenge-003/fjwhittle/perl6/ch-1.p6 +++ b/challenge-003/fjwhittle/perl6/ch-1.p6 @@ -2,12 +2,13 @@ use v6; -subset Count of Int where * > 0; +subset Count of Int where * >= 0; #| Script to generate 5-smooth numbers unit sub MAIN( Count :n(:$count) = 20, #= How many 5-smooth numbers to generate. - *@print #= specific indices to show. + Bool :$timing = False, #= Display timing information with output. + *@print #= Specific indices to show. ); # Use a lazy list to generate 5-smooth numbers @@ -28,8 +29,21 @@ my $smooth5 = gather { } } -$smooth5.[^$count].say; +if $timing { + # This needs to be a discrete block. + { + Promise.in(1 / 100).then: &?BLOCK; + $*ERR.printf(Q:b'\r%6.2fs', (now - INIT now)); + } +} -for @print -> $n { - ($n.fmt('%7d') ~ ': ' ~ @smooth5[$n-1]).say; +$smooth5.[^$count].say if $count; + +for @print.grep(* ~~ Int).sort -> $n { + if $timing { + my $result = $smooth5[$n-1]; + (Q:b'\r%6.2fs %*d: %d').sprintf((now - INIT now), @print.max.chars, $n, $result).say; + } else { + sprintf('%*d: %d', @print.max.chars, $n, $smooth5[$n-1]).say; + } } |
