diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2022-08-26 15:52:03 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2022-08-26 15:52:03 +0200 |
| commit | 62b7679d5489db7b651dd8fa9c2e429299205a19 (patch) | |
| tree | 43ccbdef0a86939325569ec1e50dc0b160d075cf /challenge-179 | |
| parent | 0e2abad9cf792a42a5c2d486de429979b0c147e5 (diff) | |
| parent | fc1d2d045a1151eab74dfb69dea9fd2736c24023 (diff) | |
| download | perlweeklychallenge-club-62b7679d5489db7b651dd8fa9c2e429299205a19.tar.gz perlweeklychallenge-club-62b7679d5489db7b651dd8fa9c2e429299205a19.tar.bz2 perlweeklychallenge-club-62b7679d5489db7b651dd8fa9c2e429299205a19.zip | |
Solutions to challenge 179
Diffstat (limited to 'challenge-179')
| -rwxr-xr-x | challenge-179/jo-37/perl/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-179/jo-37/perl/ch-2.pl | 37 |
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..4b0f69da83 --- /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::Round 'round'; + +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 / (($max - $min) || 1); + map chr(0x2581 + round(($_ - $min) * $scale)), @_; +} |
