From 1f8b55a1682d241a0bef0b38d2765c95affcfbd3 Mon Sep 17 00:00:00 2001 From: CY Fung Date: Wed, 24 Aug 2022 17:37:36 +0800 Subject: Week 179 --- challenge-179/cheok-yin-fung/perl/ch-2.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-179/cheok-yin-fung/perl/ch-2.pl 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 ""; -- cgit