From 6a2bfb87f57ececed07aaff17064d862f22b5ec1 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 22 Aug 2022 15:46:27 +0100 Subject: - Added guest contributions by Eric Cheung. --- challenge-179/eric-cheung/python/ch-1.py | 6 ++++++ challenge-179/eric-cheung/python/ch-2.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 challenge-179/eric-cheung/python/ch-1.py create mode 100755 challenge-179/eric-cheung/python/ch-2.py (limited to 'challenge-179') diff --git a/challenge-179/eric-cheung/python/ch-1.py b/challenge-179/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..6ab2c37ac5 --- /dev/null +++ b/challenge-179/eric-cheung/python/ch-1.py @@ -0,0 +1,6 @@ + +from num2words import num2words + +print (num2words(11).replace("-", " ")) +print (num2words(62).replace("-", " ")) +print (num2words(99).replace("-", " ")) diff --git a/challenge-179/eric-cheung/python/ch-2.py b/challenge-179/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..94c09ffbfd --- /dev/null +++ b/challenge-179/eric-cheung/python/ch-2.py @@ -0,0 +1,29 @@ +## -*- coding: utf-8 -*- + +## Unicode: 9601, 9602, 9603, 9604, 9605, 9606, 9607, 9608 +bar = '▁▂▃▄▅▆▇█' +barcount = len(bar) + +def sparkline(numbers): + mn, mx = min(numbers), max(numbers) + extent = mx - mn + sparkline = ''.join(bar[min([barcount - 1, int((n - mn) / extent * barcount)])] for n in numbers) + return mn, mx, sparkline + + +if __name__ == '__main__': + import re + + for line in ("0 0 1 1; 0 1 19 20; 0 999 4000 4999 7000 7999;" + "1 2 3 4 5 6 7 8 7 6 5 4 3 2 1;" + "1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5 ").split(';'): + + print("\nNumbers:", line) + + numbers = [float(n) for n in re.split(r'[\s,]+', line.strip())] + + mn, mx, sp = sparkline(numbers) + + print(' min: %5f; max: %5f' % (mn, mx)) + print(" " + sp) + -- cgit