Skip to content

Instantly share code, notes, and snippets.

@JnyJny
Created July 3, 2021 16:48
Show Gist options
  • Save JnyJny/2e477916dc8c8c4b87edb038f62a773f to your computer and use it in GitHub Desktop.
Save JnyJny/2e477916dc8c8c4b87edb038f62a773f to your computer and use it in GitHub Desktop.
Which list of numbers is bigger?
#!/usr/bin/env python3
from string import digits
from typing import List, Tuple
def make_number_lists(base: str = None) -> Tuple[List[str], List[str]]:
base = base or digits[1:]
fwidth = len(base)
a = [base[: n + 1].ljust(fwidth, "0") for n in range(fwidth)]
b = [value[::-1] for value in a]
return (a, b)
def compare_lists(list0: List[str], list1: List[str]) -> None:
sum_list0 = sum(map(int, list0))
sum_list1 = sum(map(int, list1))
fwidth = max([len(element) for element in list0])
for x, y in zip(reversed(list0), reversed(list1)):
if x == list0[0]:
print(f"+{x} +{y}")
else:
print(f" {x} {y}")
bar = "-" * (fwidth + 1)
print(" ".join([bar, bar]))
print(sum_list0, sum_list1)
if __name__ == "__main__":
a, b = make_number_lists()
compare_lists(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment