From ebd856ad7f9be363073598af45a200d448cef9c8 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 28 Aug 2022 18:46:24 +1000 Subject: sgreen solutions to challenge 179 --- challenge-179/sgreen/python/ch-2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 challenge-179/sgreen/python/ch-2.py (limited to 'challenge-179/sgreen/python/ch-2.py') diff --git a/challenge-179/sgreen/python/ch-2.py b/challenge-179/sgreen/python/ch-2.py new file mode 100755 index 0000000000..7647b00b1e --- /dev/null +++ b/challenge-179/sgreen/python/ch-2.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import sys + + +def main(strings): + numbers = [float(x) for x in strings] + bar = '▁▂▃▄▅▆▇█' + barcount = len(bar) + + mn, mx = min(numbers), max(numbers) + extent = mx - mn + sparkline = ''.join(bar[min([barcount - 1, + int((n - mn) / extent * barcount)])] + for n in numbers) + print(sparkline) + + +if __name__ == '__main__': + main(sys.argv[1:]) -- cgit