aboutsummaryrefslogtreecommitdiff
path: root/challenge-179
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-08-24 13:05:30 +0100
committerGitHub <noreply@github.com>2022-08-24 13:05:30 +0100
commit05aff8e716f22901509e2ccb9e8edd196c4a8ec4 (patch)
treef12f88ce30e747fed5a870e6cc08707c1287be08 /challenge-179
parent51c906c41cbdead593cf8680c225911f9d7ab0ae (diff)
parent1f8b55a1682d241a0bef0b38d2765c95affcfbd3 (diff)
downloadperlweeklychallenge-club-05aff8e716f22901509e2ccb9e8edd196c4a8ec4.tar.gz
perlweeklychallenge-club-05aff8e716f22901509e2ccb9e8edd196c4a8ec4.tar.bz2
perlweeklychallenge-club-05aff8e716f22901509e2ccb9e8edd196c4a8ec4.zip
Merge pull request #6649 from E7-87-83/newt
Week 179
Diffstat (limited to 'challenge-179')
-rw-r--r--challenge-179/cheok-yin-fung/perl/ch-2.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-179/cheok-yin-fung/perl/ch-2.pl b/challenge-179/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..dba8911da8
--- /dev/null
+++ b/challenge-179/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,26 @@
+# The Weekly Challenge 179
+# Task 2 Unicode Sparkline
+use v5.30.0;
+use List::Util qw/max min uniq/;
+use POSIX;
+binmode(STDOUT, ":utf8");
+
+my @n = @ARGV;
+
+exit unless defined($ARGV[1]);
+
+my @nn = map {$_ / min(@n)} @n;
+
+my @s_n = sort {$a <=> $b} @nn;
+my $diff = max map {$s_n[$_+1]-$s_n[$_]} (0..$#s_n-1);
+
+my $step = min( (max @nn)/8 , $diff ) ;
+$step = (max @nn)/6 if $step == 0;
+
+foreach (@nn) {
+ my $h = 9600 + floor( $_ / $step + 0.5);
+ $h = 9601 if $h < 9601; #security
+ $h = 9608 if $h > 9608; #security
+ print pack("U*", $h);
+}
+say "";