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/2023/03_GearRatios.py at main · wolflu05/AdventOfCode Expand file tree/ Copy path03_GearRatios.pyMore file actions 37 lines (28 loc) · 966 Bytes / Copy path03_GearRatios.pyFile metadata and controls37 lines (28 loc) · 966 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 37 from lib import * inp = get_input() p1 = 0 gears = {} for y in range(len(inp)): num = "" has_sym = False num_gears = set() for x in range(len(inp[y])): if inp[y][x].isdigit(): num += inp[y][x] for yy, xx in iterate_positions(y, x, get_positions(), inp): if inp[yy][xx] != "." and not inp[yy][xx].isdigit(): has_sym = True if inp[yy][xx] == "*": num_gears.add((yy, xx)) if (x + 1) > (len(inp[y]) - 1) or not inp[y][x + 1].isdigit(): if has_sym: num = int(num) p1 += num for yyy, xxx in num_gears: gears.setdefault((yyy, xxx), []).append(num) num = "" has_sym = False num_gears = set() p2 = sum(nums[0] * nums[1] for nums in gears.values() if len(nums) == 2) 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. |