How to resolve the algorithm Sparkline in unicode step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sparkline in unicode step by step in the zkl programming language

Table of Contents

Problem Statement

A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession.

Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a sparkline-type bar graph of the values on a single line of output. The eight characters: '▁▂▃▄▅▆▇█' (Unicode values U+2581 through U+2588). Use your program to show sparklines for the following input, here on this page:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sparkline in unicode step by step in the zkl programming language

Source code in the zkl programming language

var sparks=[0x2581..0x2588].apply("toString",-8); // int.toString(-8)-->UTF-8
var sl=(sparks.len()-1);
 
fcn sparkLine(xs){
   min:=(0.0).min(xs); max:=(0.0).max(xs);  // min/max are float reguardless of xs
   range:=max-min;  // float
   println("Range [",min,"-",max,"]", xs);
   xs.pump(String,'wrap(x){ sparks[(x - min)*sl/range] }).println();
}

one:="1 2 3 4 5 6 7 8 7 6 5 4 3 2 1".split(" ").apply("toInt");
two:=("1.5, 0.5 3.5, 2.5 5.5 4.5 7.5, 6.5" - ",").split(" ").apply("toFloat");
sparkLine(one); sparkLine(two);

  

You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Beads programming language
You may also check:How to resolve the algorithm Dijkstra's algorithm step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Barnsley fern step by step in the J programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the E programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Lambdatalk programming language