GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AdventOfCode/languages/py/2024/07_BridgeRepair.py at main · wolflu05/AdventOfCode Expand file tree/ Copy path07_BridgeRepair.pyMore file actions 36 lines (31 loc) · 894 Bytes / Copy path07_BridgeRepair.pyFile metadata and controls36 lines (31 loc) · 894 Bytes 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 import itertools, math from lib import * inp = get_input() p1 = 0 p2 = 0 for l in inp: r, nums = l.split(": ") r, nums = int(r), [int(x) for x in nums.split()] has_p1 = False has_p2 = False for ops in itertools.product("*+|", repeat=len(nums)-1): e = nums[0] for i, op in enumerate(ops): if op == "*": e *= nums[i+1] elif op == "+": e += nums[i+1] elif op == "|": # ---- num of digits in nums[i+1] ---- e = e * 10**(math.floor(math.log10(nums[i+1]))+1) + nums[i+1] if e == r: if not has_p1 and "|" not in ops: p1 += r has_p1 = True if not has_p2: p2 += r has_p2 = True if has_p1 and has_p2: break print(p1) print(p2) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |