diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-08-26 22:05:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-26 22:05:23 +0100 |
| commit | 32c6a03c2bbe28a8710adf22b28aa644f68c64b8 (patch) | |
| tree | 77aca1e1971394060e52027755820ad86f46b0f8 | |
| parent | 0e2abad9cf792a42a5c2d486de429979b0c147e5 (diff) | |
| parent | 138e6f00cd7a994f5e63d403c40eb94faa76abd3 (diff) | |
| download | perlweeklychallenge-club-32c6a03c2bbe28a8710adf22b28aa644f68c64b8.tar.gz perlweeklychallenge-club-32c6a03c2bbe28a8710adf22b28aa644f68c64b8.tar.bz2 perlweeklychallenge-club-32c6a03c2bbe28a8710adf22b28aa644f68c64b8.zip | |
Merge pull request #6654 from jo-37/contrib
Solutions 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..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)), @_; +} |
