From b99bab8e4715ad585fed2be153e142eec7c6c0d3 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 22 Aug 2022 23:33:48 +0200 Subject: Solve 179: Ordinal Number Spelling & Unicode Sparkline by E. Choroba --- challenge-179/e-choroba/perl/ch-1.pl | 12 ++++++++++++ challenge-179/e-choroba/perl/ch-2.pl | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 challenge-179/e-choroba/perl/ch-1.pl create mode 100755 challenge-179/e-choroba/perl/ch-2.pl (limited to 'challenge-179') 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), '▁▂▃▄▅▆▇█'; -- cgit