Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Sparkline-in-unicode/F-Sharp/sparkline-in-unicode.fs
Normal file
22
Task/Sparkline-in-unicode/F-Sharp/sparkline-in-unicode.fs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
open System
|
||||
open System.Globalization
|
||||
open System.Text.RegularExpressions
|
||||
|
||||
let bars = Array.map Char.ToString ("▁▂▃▄▅▆▇█".ToCharArray())
|
||||
|
||||
while true do
|
||||
printf "Numbers separated by anything: "
|
||||
let numbers =
|
||||
[for x in Regex.Matches(Console.ReadLine(), @"-?\d+(?:\.\d*)?") do yield x.Value]
|
||||
|> List.map (fun x -> Double.Parse(x, CultureInfo.InvariantCulture))
|
||||
if numbers.Length = 0 then System.Environment.Exit(0)
|
||||
if numbers.Length = 1 then
|
||||
printfn "A sparkline for 1 value is not very useful... ignoring entry"
|
||||
else
|
||||
let min, max = List.min numbers, List.max numbers
|
||||
printfn "min: %5f; max: %5f" min max
|
||||
let barsCount = float (bars.GetUpperBound(0))
|
||||
numbers
|
||||
|> List.map (fun x -> bars.[int ((x - min)/(max - min) * barsCount)])
|
||||
|> String.Concat
|
||||
|> printfn "%s"
|
||||
Loading…
Add table
Add a link
Reference in a new issue