diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-08-29 03:25:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 03:25:46 +0100 |
| commit | 454d902035438fc1fae40e978aa32bb072f6f7f5 (patch) | |
| tree | ef0c7deeb03c0990124ef7ab184cc6deba8537ed | |
| parent | a5a0ce699f3a3a0f647b55693842156465a3404f (diff) | |
| parent | b5011ef51139162a547d3f80a4743ec57bf78838 (diff) | |
| download | perlweeklychallenge-club-454d902035438fc1fae40e978aa32bb072f6f7f5.tar.gz perlweeklychallenge-club-454d902035438fc1fae40e978aa32bb072f6f7f5.tar.bz2 perlweeklychallenge-club-454d902035438fc1fae40e978aa32bb072f6f7f5.zip | |
Merge pull request #6661 from arnesom/branch-for-challenge-179
Arne Sommer
| -rw-r--r-- | challenge-179/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/ch-1.raku | 57 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/ch-2.raku | 7 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/ons | 54 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/ons100 | 57 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/unicode-sparkline | 7 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/unicode-sparkline-space | 18 | ||||
| -rwxr-xr-x | challenge-179/arne-sommer/raku/unicode-sparkline-verbose | 22 |
8 files changed, 223 insertions, 0 deletions
diff --git a/challenge-179/arne-sommer/blog.txt b/challenge-179/arne-sommer/blog.txt new file mode 100644 index 0000000000..b06a82223f --- /dev/null +++ b/challenge-179/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/ordinal-spark.html diff --git a/challenge-179/arne-sommer/raku/ch-1.raku b/challenge-179/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..2160886ce7 --- /dev/null +++ b/challenge-179/arne-sommer/raku/ch-1.raku @@ -0,0 +1,57 @@ +#! /usr/bin/env raku + +unit sub MAIN (UInt $integer); + +my %mapping = +( + 0 => "zeroth", + 1 => "first", + 2 => "second", + 3 => "third", + 4 => "fourth", + 5 => "fifth", + 6 => "sixth", + 7 => "seventh", + 8 => "eighth", + 9 => "ninth", + 10 => "tenth", + 11 => "eleventh", + 12 => "twelfth", + 13 => "thirteenth", + 14 => "fourteenth", + 15 => "fifteenth", + 16 => "sixteenth", + 17 => "seventeenth", + 18 => "eighteenth", + 19 => "nineteenth", + 20 => "twenty", + '2x' => "twentieth", + 30 => "thirty", + '3x' => "thirtieth", + 40 => "forty", + '4x' => "fortieth", + 50 => "fifty", + '5x' => "fiftieth", + 60 => "sixty", + '6x' => "sixtieth", + 70 => "seventieth", + '7x' => "seventy", + 80 => "eightieth", + '8x' => "eighty", + 90 => "ninetieth", + '9x' => "ninety", + 100 => "hundreth", + 1000 => "thousandth", +); + +if %mapping{$integer} +{ + say %mapping{$integer}; +} +else +{ + die "Unsupported value. Use 0-100,1000 only" if $integer.chars > 2; + my ($first, $second) = $integer.comb; + + say "{ %mapping{$first ~ "x"} }-{ %mapping{$second} }"; +} diff --git a/challenge-179/arne-sommer/raku/ch-2.raku b/challenge-179/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..64662dd959 --- /dev/null +++ b/challenge-179/arne-sommer/raku/ch-2.raku @@ -0,0 +1,7 @@ +#! /usr/bin/env raku + +subset PositiveInt of Int where * > 0; + +unit sub MAIN (*@numbers where @numbers.elems > 0 && all(@numbers) ~~ PositiveInt); + +say @numbers.map({ "▁▂▃▄▅▆▇█".comb.[$_ / max(@numbers) * 7] }).join; diff --git a/challenge-179/arne-sommer/raku/ons b/challenge-179/arne-sommer/raku/ons new file mode 100755 index 0000000000..6b9c14a7d8 --- /dev/null +++ b/challenge-179/arne-sommer/raku/ons @@ -0,0 +1,54 @@ +#! /usr/bin/env raku + +unit sub MAIN (UInt $integer where $integer <= 99); + +my %mapping = +( + 0 => "zeroth", + 1 => "first", + 2 => "second", + 3 => "third", + 4 => "fourth", + 5 => "fifth", + 6 => "sixth", + 7 => "seventh", + 8 => "eighth", + 9 => "ninth", + 10 => "tenth", + 11 => "eleventh", + 12 => "twelfth", + 13 => "thirteenth", + 14 => "fourteenth", + 15 => "fifteenth", + 16 => "sixteenth", + 17 => "seventeenth", + 18 => "eighteenth", + 19 => "nineteenth", + 20 => "twenty", + '2x' => "twentieth", + 30 => "thirty", + '3x' => "thirtieth", + 40 => "forty", + '4x' => "fortieth", + 50 => "fifty", + '5x' => "fiftieth", + 60 => "sixty", + '6x' => "sixtieth", + 70 => "seventieth", + '7x' => "seventy", + 80 => "eightieth", + '8x' => "eighty", + 90 => "ninetieth", + '9x' => "ninety", +); + +if %mapping{$integer} +{ + say %mapping{$integer}; +} +else +{ + my ($first, $second) = $integer.comb; + + say "{ %mapping{$first ~ "x"} }-{ %mapping{$second} }"; +} diff --git a/challenge-179/arne-sommer/raku/ons100 b/challenge-179/arne-sommer/raku/ons100 new file mode 100755 index 0000000000..2160886ce7 --- /dev/null +++ b/challenge-179/arne-sommer/raku/ons100 @@ -0,0 +1,57 @@ +#! /usr/bin/env raku + +unit sub MAIN (UInt $integer); + +my %mapping = +( + 0 => "zeroth", + 1 => "first", + 2 => "second", + 3 => "third", + 4 => "fourth", + 5 => "fifth", + 6 => "sixth", + 7 => "seventh", + 8 => "eighth", + 9 => "ninth", + 10 => "tenth", + 11 => "eleventh", + 12 => "twelfth", + 13 => "thirteenth", + 14 => "fourteenth", + 15 => "fifteenth", + 16 => "sixteenth", + 17 => "seventeenth", + 18 => "eighteenth", + 19 => "nineteenth", + 20 => "twenty", + '2x' => "twentieth", + 30 => "thirty", + '3x' => "thirtieth", + 40 => "forty", + '4x' => "fortieth", + 50 => "fifty", + '5x' => "fiftieth", + 60 => "sixty", + '6x' => "sixtieth", + 70 => "seventieth", + '7x' => "seventy", + 80 => "eightieth", + '8x' => "eighty", + 90 => "ninetieth", + '9x' => "ninety", + 100 => "hundreth", + 1000 => "thousandth", +); + +if %mapping{$integer} +{ + say %mapping{$integer}; +} +else +{ + die "Unsupported value. Use 0-100,1000 only" if $integer.chars > 2; + my ($first, $second) = $integer.comb; + + say "{ %mapping{$first ~ "x"} }-{ %mapping{$second} }"; +} diff --git a/challenge-179/arne-sommer/raku/unicode-sparkline b/challenge-179/arne-sommer/raku/unicode-sparkline new file mode 100755 index 0000000000..64662dd959 --- /dev/null +++ b/challenge-179/arne-sommer/raku/unicode-sparkline @@ -0,0 +1,7 @@ +#! /usr/bin/env raku + +subset PositiveInt of Int where * > 0; + +unit sub MAIN (*@numbers where @numbers.elems > 0 && all(@numbers) ~~ PositiveInt); + +say @numbers.map({ "▁▂▃▄▅▆▇█".comb.[$_ / max(@numbers) * 7] }).join; diff --git a/challenge-179/arne-sommer/raku/unicode-sparkline-space b/challenge-179/arne-sommer/raku/unicode-sparkline-space new file mode 100755 index 0000000000..9b4b5263f3 --- /dev/null +++ b/challenge-179/arne-sommer/raku/unicode-sparkline-space @@ -0,0 +1,18 @@ +#! /usr/bin/env raku + +subset PositiveInt of Int where * > 0; + +unit sub MAIN (*@numbers where @numbers.elems > 0 && all(@numbers) ~~ PositiveInt, :s(:$use-space)); + +my $max = max(@numbers); + +my @chars = $use-space + ?? " ▁▂▃▄▅▆▇█".comb + !! "▁▂▃▄▅▆▇█".comb; + +for @numbers -> $c +{ + print @chars[$c / $max * (@chars.elems - 1)]; +} + +say ""; diff --git a/challenge-179/arne-sommer/raku/unicode-sparkline-verbose b/challenge-179/arne-sommer/raku/unicode-sparkline-verbose new file mode 100755 index 0000000000..ebb4e8ee0a --- /dev/null +++ b/challenge-179/arne-sommer/raku/unicode-sparkline-verbose @@ -0,0 +1,22 @@ +#! /usr/bin/env raku + +subset PositiveInt of Int where * > 0; + +unit sub MAIN (*@numbers where @numbers.elems > 0 && all(@numbers) ~~ PositiveInt, :v(:$verbose)); + +my $max = max(@numbers); + +my @chars = "▁▂▃▄▅▆▇█".comb; + +my @output; + +for @numbers -> $c +{ + my $index = $c / $max * (@chars.elems - 1); + + say ": $c -> $index" if $verbose; + + @output.push: @chars[$index]; +} + +say @output.join; |
