aboutsummaryrefslogtreecommitdiff
path: root/challenge-179
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2022-08-22 23:33:48 +0200
committerE. Choroba <choroba@matfyz.cz>2022-08-22 23:33:48 +0200
commitb99bab8e4715ad585fed2be153e142eec7c6c0d3 (patch)
tree58e8252599107dd125057671c5eb147a600457db /challenge-179
parent6a2bfb87f57ececed07aaff17064d862f22b5ec1 (diff)
downloadperlweeklychallenge-club-b99bab8e4715ad585fed2be153e142eec7c6c0d3.tar.gz
perlweeklychallenge-club-b99bab8e4715ad585fed2be153e142eec7c6c0d3.tar.bz2
perlweeklychallenge-club-b99bab8e4715ad585fed2be153e142eec7c6c0d3.zip
Solve 179: Ordinal Number Spelling & Unicode Sparkline by E. Choroba
Diffstat (limited to 'challenge-179')
-rwxr-xr-xchallenge-179/e-choroba/perl/ch-1.pl12
-rwxr-xr-xchallenge-179/e-choroba/perl/ch-2.pl19
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), '▁▂▃▄▅▆▇█';