-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcounting.py
102 lines (96 loc) · 1.92 KB
/
counting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import random
from num2words import num2words
# maintaining this list should not be necessary once
# https://github.com/savoirfairelinux/num2words/pull/208,
# which implements supported_lang, is merged and released
languages = [
'en',
'ar',
'cz',
'de',
'dk',
'en_GB',
'en_IN',
'es',
'es_CO',
'es_VE',
# 'eu', # not implemented
'fi',
'fr',
'fr_CH',
'fr_BE',
'fr_DZ',
'he',
'id',
'it',
'ja',
'kn',
'ko',
'lt',
'lv',
'no',
'pl',
'pt',
'pt_BR',
'sl',
'sr',
'ro',
'ru',
'sl',
'tr',
'th',
'vi',
'nl',
'uk'
]
def count(ns):
"""
Manager for randomizing counting systems;
input is expected to be zero-based, and output is
one-based.
"""
r = random.random()
if r < 0.2:
return [str(n + 1) for n in ns]
elif r < 0.4:
return [yan_tan(n) for n in ns]
else:
while True:
try:
language = random.choice(languages)
return [num2words(n + 1, lang=language) for n in ns]
except NotImplementedError:
pass
def yan_tan(n):
"""
from https://en.wikipedia.org/wiki/Yan_tan_tethera
input is expected to be zero-based
"""
systems = {
'lincolnshire': [
'yan',
'teyan',
'tethera',
'methera',
'tic',
'yan-a-tic',
'teyan-a-tic',
'tethera-tic',
'methera-tic',
'bub',
'yan-a-bub',
'teyan-a-bub',
'tethera-bub',
'methera-bub',
'tic-a-bub',
'yan-tic-a-bub',
'teyan-tic-a-bub',
'tethera-tic-a-bub',
'methera-tic-a-bub',
'gigget'
]
}
try:
return systems['lincolnshire'][n]
except IndexError:
return str(n + 1)