Skip to content

Commit

Permalink
Added a switch to the command line, also added some comments for bett…
Browse files Browse the repository at this point in the history
…er description
  • Loading branch information
carbeck committed Feb 8, 2015
1 parent dc227c4 commit 9edfeca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ Executing the Script
You'll need Python 3 for this. Note that this is a *command-line program*. `python ayerinumbers.py -h` gives you some advice on the input:

positional arguments:
n An integer number between 0 and (10^40)₁₂
n an integer number n >= 0

optional arguments:
-h, --help show this help message and exit
-s, --show-conversion show the conversion into base 12

Some output examples:

$ ./ayerinumbers.py 54292
27504: samang sam menang itolan-iri nay yo
samang sam menang itolan-iri nay yo

$ ./ayerinumbers.py 5106212
1862B98: samang menang men henlan-miye menang samlan-tam veyalan-hen
samang menang men henlan-miye menang samlan-tam veyalan-hen

$ ./ayerinumbers.py 636
450: menang yo irilan
menang yo irilan

$ ./ayerinumbers.py 20736
10000: samang men
$ ./ayerinumbers.py -s 20736
10000₁₂: samang men

$ ./ayerinumbers.py 3457
2001: menang samlan nay men
$ ./ayerinumbers.py --show-conversion 3457
2001₁₂: menang samlan nay men

Disclaimer
----------
Expand Down
30 changes: 24 additions & 6 deletions ayerinumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def c(n):

def baseconv(n, b = 12):
'''Convert an integer number n in base 10 to another'''
n = int(math.floor(float(n)))
s = ''
while n > 0:
r = n % b # remainder
Expand Down Expand Up @@ -121,13 +120,21 @@ def numword_bigram(n, pn = 'nword'):

def rsplit_str(s, i):
'''Splits string after i digits from the back'''

# Containers
chars = ''
spl = []

# Calculate the modulo the last index results in for the length of the group
# 12345, split into groups of max. 3 => last index: 4, 4 % 3 = 1
m = (len(s) - 1) % i

for n, char in enumerate(s):
chars += char;
if n % i == (len(s) - 1) % i:
if n % i == m:
spl.append(chars);
chars = ''

return spl

def split_num(s):
Expand All @@ -150,10 +157,15 @@ def get_power(i):
'''Gets the word for the respective power from number of elements'''
pow = i * 2 - 2

# In case it's already readily defined
if pow in pword:
return pword[pow]

# In case it's not already defined
elif pow not in pword and pow < max(pword):

# Iterate through all the power words until one bigger than the input
# is found, use the previous one then.
flag = True
p = 0
while flag:
Expand Down Expand Up @@ -206,12 +218,18 @@ def main(argv=None):
# Parser for command line options
parser = argparse.ArgumentParser(description=
"Converts numbers to Ayeri number words.")
parser.add_argument('n', type=str, help='''An integer number between 0 and
(10^40)₁₂''')

parser.add_argument('n', type=int, help='''an integer number >= 0''')
parser.add_argument('-s', '--show-conversion', action='store_const',
const=True, default=False, help='''show the conversion into base 12'''),
args = parser.parse_args(argv)

return '{}₁₂: {}'.format(baseconv(args.n), numberword(baseconv(args.n)))
# Return string
s = ''
if args.show_conversion:
s += '{}₁₂: '.format(baseconv(args.n))
s += '{}'.format(numberword(baseconv(args.n)))

return s

if __name__ == '__main__':
sys.exit(main())

0 comments on commit 9edfeca

Please sign in to comment.