Skip to content

Instantly share code, notes, and snippets.

@theelous3
Created May 26, 2020 18:16
Show Gist options
  • Save theelous3/9ba59d1316b10b2ea84be6ca58506892 to your computer and use it in GitHub Desktop.
Save theelous3/9ba59d1316b10b2ea84be6ca58506892 to your computer and use it in GitHub Desktop.
>>> from collections import deque
>>>
>>> def ldp(n, current=60):
... # largest_divisible_power
... s = 1
... while n > current:
... current = current ** s
... s += 1
... return s - 2
...
>>>
>>> def ntb(n):
... # num to babylonian representation
... char_map = {
... 1000000:";",
... 100000: "|",
... 10000: "=",
... 1000: "~",
... 100: ">",
... 10: "<",
... 1: "^"
... }
... n_power_map = deque()
... power = 1
... for n in reversed(str(n)):
... n_power_map.appendleft((n, power))
... power *= 10
... representation = ""
... for num, power_ in n_power_map:
... num = int(num)
... representation += char_map[power_] * num
... return representation
...
>>>
>>> def base_60(d):
... # convert decimal `d` in to modernised babylonian base 60
... modulus = 60
... number_parts = deque()
... while d >= 60:
... largest_power = ldp(d)
... current = 60 ** largest_power
... times_in_to_d = int(d / current)
... remainder = d / current % 1
... d = d - current * times_in_to_d
... number_parts.append(times_in_to_d)
... number_parts.append(d)
... current_representation = [ntb(num) for num in number_parts]
... return " ".join(current_representation)
...
>>> print(f"""
... 13 == {base_60(13)}
... 149 == {base_60(149)}
... 12345 == {base_60(12345)}
... 9999999 == {base_60(9999999)}
... """
... )
13 == <^^^
149 == ^^ <<^^^^^^^^^
12345 == ^^^ <<^^^^^ <<<<^^^^^
9999999 == ~~>>>>>>><<<<<<<^^^^^^^ <<<<^^^^^^ <<<^^^^^^^^^
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment