Sparkline in unicode: Difference between revisions

Updated to work with Nim 1.4: changed "True" to "true"; added import of "sequtils" (for "map"). Also, used directly the UTF-8 strings for the chars (no need for module "unicode"), changed precision to -1, added "filterIt"..
m (→‎{{header|Phix}}: no_empty param is no more)
(Updated to work with Nim 1.4: changed "True" to "true"; added import of "sequtils" (for "map"). Also, used directly the UTF-8 strings for the chars (no need for module "unicode"), changed precision to -1, added "filterIt"..)
Line 1,654:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import rdstdin, strutilssequtils, unicodestrutils
 
const bar = [9601"\u2581", 9602"\u2582", 9603"\u2583", 9604"\u2584", 9605"\u2585", 9606"\u2586", 9607"\u2587", 9608"\u2588"]
const barcount = float(bar.high)
 
while Truetrue:
let
line = readLineFromStdin "Numbers please separated by space/commas: "
numbers = line.split({' ', ','}).filterIt(it.len != 0).map(parseFloat)
mn = min(numbers)
mx = max(numbers)
Line 1,668:
var sparkline = ""
for n in numbers:
let i = int((n - mn) / extent * barcount)
sparkline.add($TRune( bar[i]))
echo "min: ", mn.formatFloat(precision = 0), "; max: ", mx.formatFloat(precision = 0-1)
echo sparkline</lang>
{{out}}
Anonymous user