Skip to content

Instantly share code, notes, and snippets.

@assyrianic
Forked from ledzeppelin/int_to_aii_numeral.py
Created August 29, 2023 17:36
Show Gist options
  • Save assyrianic/0722fee838bea990b813c2d4c997b4ef to your computer and use it in GitHub Desktop.
Save assyrianic/0722fee838bea990b813c2d4c997b4ef to your computer and use it in GitHub Desktop.
integer to assyrian numeral
def int_to_aii_numeral(num):
# greedy approach similar to https://leetcode.com/problems/integer-to-roman/description/
# time O(1)
# space O(1)
# based on the numerals here: https://en.wiktionary.org/wiki/Module:number_list/data/aii
numerals = [
(1000, 'ܐ݇'),
(900, 'ܨ̈'), (800, 'ܦ̈'), (700, 'ܥ̈'), (600, 'ܣ̈'), (500, 'ܢ̈'), (400, 'ܬ'),
(300, 'ܫ'), (200, 'ܪ'), (100, 'ܩ'), (90, 'ܨ'), (80, 'ܦ'), (70, 'ܥ'), (60, 'ܣ'),
(50, 'ܢ'), (40, 'ܡ'), (30, 'ܠ'), (20, 'ܟ'), (10, 'ܝ'), (9, 'ܛ'), (8, 'ܚ'), (7, 'ܙ'),
(6, 'ܘ'), (5, 'ܗ'), (4, 'ܕ'), (3, 'ܓ'), (2, 'ܒ'), (1, 'ܐ'), (0, ''),
]
aii_numerals = []
for val, numeral in numerals:
if num == 0:
break
is_divisible, num = divmod(num, val) # reassign quotient and remainder
if is_divisible:
aii_numerals.append(numeral)
return ''.join(aii_numerals) + '.'
assert int_to_aii_numeral(0) == '.'
assert int_to_aii_numeral(1) == 'ܐ.'
assert int_to_aii_numeral(9) == 'ܛ.'
assert int_to_aii_numeral(10) == 'ܝ.'
assert int_to_aii_numeral(11) == 'ܝܐ.'
assert int_to_aii_numeral(77) == 'ܥܙ.'
assert int_to_aii_numeral(90) == 'ܨ.'
assert int_to_aii_numeral(99) == 'ܨܛ.'
assert int_to_aii_numeral(1999) == 'ܐ݇ܨ̈ܨܛ.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment