Sparkline in unicode: Difference between revisions

Content deleted Content added
Markjreed (talk | contribs)
→‎{{header|Clojure}}: Add implementation
Line 138:
Min: 0.5; Max: 7.5; Range: 7
▂▁▄▃▆▅█▇</pre>
 
=={{header|Clojure}}==
<lang Clojure>(defn sparkline [nums]
(let [sparks "▁▂▃▄▅▆▇█"
high (apply max nums)
low (apply min nums)
spread (- high low)
quantize #(Math/round (* 7.0 (/ (- % low) spread)))]
(apply str (map #(nth sparks (quantize %)) nums))))
 
(defn spark [line]
(if line
(let [nums (read-string (str "[" line "]"))]
(println (sparkline nums))
(recur (read-line)))))
 
(spark (read-line))</lang>
 
{{Out}}
<pre>$ clj sparkline.clj <<<$'1 2 3 4 5 6 7 8 7 6 5 4 3 2 1\n1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5'
▁▂▃▄▅▆▇█▇▆▅▄▃▂▁
▂▁▄▃▆▅█▇
</pre>
 
=={{header|D}}==