ref: 3703478dcfedd048437f7a0515dbda2ff8a22d8d
2019/001/main.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 |
def round_down(value): integer = int(value) if integer == value: return value return integer def calculate(value): if value <= 0: return 0 v = round_down(value / 3.0) - 2 if v <= 0: return 0 return v + calculate(v) def main(): print(calculate(1969)) print('---') assert calculate(1969) == 966 print(calculate(100756)) assert calculate(100756) == 50346 data = open('input').read().splitlines() total = 0 for line in data: required = calculate(int(line)) total += required print(total) if __name__ == '__main__': main() |