diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-08-23 14:03:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 14:03:07 +0100 |
| commit | 24efc0ac2b6d12f330051fb30c1f8c79c9d83a64 (patch) | |
| tree | 3e1e315880832625bda916abb80b05b7582064f4 | |
| parent | f67787786d6c5d0f661e2f6ad10ef059694e84b6 (diff) | |
| parent | b99bab8e4715ad585fed2be153e142eec7c6c0d3 (diff) | |
| download | perlweeklychallenge-club-24efc0ac2b6d12f330051fb30c1f8c79c9d83a64.tar.gz perlweeklychallenge-club-24efc0ac2b6d12f330051fb30c1f8c79c9d83a64.tar.bz2 perlweeklychallenge-club-24efc0ac2b6d12f330051fb30c1f8c79c9d83a64.zip | |
Merge pull request #6644 from choroba/ech179
Solve 179: Ordinal Number Spelling & Unicode Sparkline by E. Choroba
| -rwxr-xr-x | challenge-179/e-choroba/perl/ch-1.pl | 12 | ||||
| -rwxr-xr-x | challenge-179/e-choroba/perl/ch-2.pl | 19 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-179/e-choroba/perl/ch-1.pl b/challenge-179/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..6b3984faed --- /dev/null +++ b/challenge-179/e-choroba/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Lingua::EN::Numbers (); + +*ordinal_number_spelling = *Lingua::EN::Numbers::num2en_ordinal; + +use Test::More tests => 3; +is ordinal_number_spelling(11), 'eleventh', 'Example 1'; +is ordinal_number_spelling(62), 'sixty-second', 'Example 2'; +is ordinal_number_spelling(99), 'ninety-ninth', 'Example 3'; diff --git a/challenge-179/e-choroba/perl/ch-2.pl b/challenge-179/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..79cae1dbc3 --- /dev/null +++ b/challenge-179/e-choroba/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use warnings; +use strict; +use utf8; +use experimental 'signatures'; + +use POSIX qw{ round }; +use List::Util qw{ min max }; + +my @BLOCKS = split //, '▁▂▃▄▅▆▇█'; +sub unicode_sparkline (@n) { + my ($min, $max) = (min(@n), max(@n)); + my $step = ($max - $min) / 7; + return join "", @BLOCKS[map round(($_ - $min) / $step), @n] +} + +use Test::More tests => 1; + +is unicode_sparkline(map $_ * 2.3, 1 .. 8), '▁▂▃▄▅▆▇█'; |
