#Day 3 Gear Ratios
1 messages · Page 1 of 1 (latest)
this is the stupidest fucking engine schematic ive ever seen
elves are terrible engineers
no surprise, they ruin christmas every year
Oh another parsing exercise..
Wow. This problem looks hard enough to do in a normal language.
Oh honey new the AoC problem is up
I had sleep plans but I guess I can be up when it's almost morning
hooooly mother
More parsing indeed
If they keep on this trajectory, I might have to drop out now. I'm pretty sure I could do this, but these are taking me hours and I really need to do other things.
historically speaking, they definitely will
But they feel a lot harder this year. Unless I'm just remembering poorly.
It's my first time doing AoC but so far this is the only one that looks fairly difficult
i love string manipulation so much
both parts C++
I should make an mdspan LayoutPolicy to handle oob access for these
I need a shower after writing this code. At least it's done.
both parts in python
||
#!/usr/bin/env python3
import math
def getnum(s: str, i: int) -> int:
l, r = i, i
while (0 <= l - 1) and (s[l - 1].isdigit()):
l -= 1
while (r + 1 < W) and (s[r + 1].isdigit()):
r += 1
return int(s[l : r + 1])
p1, p2 = 0, 0
adj = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
G = open("input.txt").read().splitlines()
H, W = len(G), len(G[0])
for y in range(H):
for x in range(W):
sym = G[y][x]
if sym in ".0123456789":
continue
nums = set()
for i, j in adj:
i, j = i + y, j + x
if G[i][j].isdigit():
nums.add(getnum(G[i], j))
p1 += sum(nums)
p2 += math.prod(nums) if len(nums) == 2 and sym == "*" else 0
print(p1, p2)
||
^ won't work if there are multiple numbers of same value adjacent to a symbol .. e.g. 123$123
Probably over-engineered, but it helps my brain. Github: ||https://github.com/bigbass1997/aoc-2023/blob/main/day03/src/main.rs||
Only part 1 for now, in Mr. Krabs' language, would not recommend looking because it was made in only 30min and it's just horrible. will fix it after I sleep 😴

Abusing LINQ
||```cs
var nums = world.Where(n => n.typ == otype.num);
var sum2 = world.Where(c => c.typ == otype.sym && (char)c.contents == '*')
.Select(c => c.left_coord)
.Select(g => nums.Where(n => n.surrounding().Contains(g)).Select(n => n.contents).ToArray())
.Where(gn => gn.Length == 2)
.Select(gn => gn[0] * gn[1])
.Sum();
Console.WriteLine("Part 2: " + sum2);
Just looked at part 2, will have to rewrite my code anyway because it sucks LOL
I think you can still do it with some adjustments. In general I always just parse everything to a manageable data structure first. It's more code, but most of the time it helps
I was gonna do that, I had a pretty little struct I was proud to make, then decided I was too sleep deprived to bother. I'll probably bring it back after I wake up lmao
I guess I just wanted to make a dumb and naive solution to validate my first idea
improved simplified solution
@knotty ermine for part2 .filter shouldn't it be .. numbers.count() == 2 ?
nevermind, just checked my own input ... there are no symbols that have more than 2 adjacent numbers
technically yes but yeah it never happens in the input
||I’m surprised there’s no gotcha in the input where a number is attached to two gears||
my script would be ok with that, .. but wouldn't be able to handle this || 123*123|||
While I was reading the question, I feared whether or not ||we had to wrap around to the opposite edge of the data. But didn't seem to be the case in the end. The directions never explicitly mentioned such a scenario.||
😨 that would be cruel
hehe cruelty wouldn't stop AoC from doing it.
then we should also add numbers that span vertically 😂
ha yeah I feared that too! since again, the instructions didn't mention them one way or another.
Something like that will definitely happen further down the month.. It always does
I'm just wondering when the first graph-theory problem will happen.
We'll get some BFS/Dijkstra again probably too. At least now I have a nice crate for that 🙂
Remainder theorem..
This is what I mean by it gets easier the more years you do 😆 You start recognizing the problems
Rust day today
Is that Rust with some custom macro wrapper?
yes. the macro is here https://github.com/maia-s/aoc/blob/main/2023/src/lib.rs
The problem from the first day is still the hardest one yet tbh
ugly haskell part 1 and 2
Finally woke up and finished part 2, too long to post here lol. Will improve later
He did day 4 easily though