diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-08-22 15:46:27 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-08-22 15:46:27 +0100 |
| commit | 6a2bfb87f57ececed07aaff17064d862f22b5ec1 (patch) | |
| tree | 30dc9771894fa597a4812f6540cf746b9dc9b41c /challenge-179 | |
| parent | 62519b42ee44971ea14b6df5a768665fd6c6bd36 (diff) | |
| download | perlweeklychallenge-club-6a2bfb87f57ececed07aaff17064d862f22b5ec1.tar.gz perlweeklychallenge-club-6a2bfb87f57ececed07aaff17064d862f22b5ec1.tar.bz2 perlweeklychallenge-club-6a2bfb87f57ececed07aaff17064d862f22b5ec1.zip | |
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-179')
| -rwxr-xr-x | challenge-179/eric-cheung/python/ch-1.py | 6 | ||||
| -rwxr-xr-x | challenge-179/eric-cheung/python/ch-2.py | 29 |
2 files changed, 35 insertions, 0 deletions
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)
+
|
