How to resolve the algorithm Sparkline in unicode step by step in the Rust programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sparkline in unicode step by step in the Rust 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 Rust programming language
Source code in the rust programming language
const BARS: &'static str = "▁▂▃▄▅▆▇█";
fn print_sparkline(s: &str){
let v = BARS.chars().collect::<Vec<char>>();
let line: String = s.replace(",", " ").split(" ")
.filter(|x| !x.is_empty())
.map(|x| v[x.parse::<f64>().unwrap().ceil() as usize - 1])
.collect();
println!("{:?}", line);
}
fn main(){
let s1 = "1 2 3 4 5 6 7 8 7 6 5 4 3 2 1";
print_sparkline(s1);
let s2 = "1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5";
print_sparkline(s2);
}
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the PL/M programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the Wren programming language
You may also check:How to resolve the algorithm Closest-pair problem step by step in the VBA programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Lush programming language
You may also check:How to resolve the algorithm Four bit adder step by step in the FreeBASIC programming language