aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-179/jo-37/perl/ch-1.sh3
-rwxr-xr-xchallenge-179/jo-37/perl/ch-2.pl37
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-179/jo-37/perl/ch-1.sh b/challenge-179/jo-37/perl/ch-1.sh
new file mode 100755
index 0000000000..fbf496c437
--- /dev/null
+++ b/challenge-179/jo-37/perl/ch-1.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+perl -MLingua::EN::Numbers=num2en_ordinal -E "say num2en_ordinal $1"
diff --git a/challenge-179/jo-37/perl/ch-2.pl b/challenge-179/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..5ff1c52ff4
--- /dev/null
+++ b/challenge-179/jo-37/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use v5.16;
+use List::MoreUtils 'minmax';
+use Math::Utils 'floor';
+
+die <<EOS unless @ARGV;
+usage: $0 N1 N2 ...
+
+N1 N2 ...
+ Numbers to be represented in a sparkline-like bar chart.
+
+EOS
+
+
+### Input and Output
+
+binmode STDOUT, ':utf8';
+say barchart(@ARGV);
+
+
+### Implementation
+
+# A vague solution for a vague task: I didn't find any Unicode
+# symbols that could be used to produce sparklines. Using
+# ${SEARCH_ENGINE} revealed some implementations that produce small
+# bar charts using Unicode symbols. Following this approach.
+#
+# Starting with U+2581 ("\N{LOWER ONE EIGHTH BLOCK}"), there are eight
+# consecutive block symbols having a height of one to eight eights that
+# will be used here. Returning a list of characters.
+
+sub barchart {
+ my ($min, $max) = minmax @_;
+ my $scale = 7.999 / (($max - $min) || 1);
+ map chr(0x2581 + floor(($_ - $min) * $scale)), @_;
+}