My method focused on finding then looking around each symbol, then adding the numbers around to a global sum (of course storing their start points in an array so we don't get the same one twice). It may have been worse, but I was very happy with the part 2 lol
@kozmicluis255210 ай бұрын
With any language that has a group-by function part 2 becomes easy as hell. All I had to do was for each number basically save the number itself along with the location of its adjacent gear (after observing that every number only had 1 or no symbol adjacent to it) if it exists. Then group by this location into a map/hashmap, get the values, filter the ones where the amount of numbers is exactly 2, then multiply both numbers on each gear, add them up, profit.
@blaise961410 ай бұрын
Great presentation. Thank you for being concise and clear with your structure.
@NicolastheThird-h6m10 ай бұрын
Great solution. I made some complicated bs, this is so much better and easier to read.
@dylansuther10 ай бұрын
This is such a smart solution. Thank you!
@willzin-da-esfiha10 ай бұрын
I've created a point struct to store position of a character. Then, I stored the number, the positions of its start and end characters. Then I pushed the info into an array. I stored the position of the symbols also. Then did some coordinates calc to check if the numbers are in range of the symbol. The part 2 was easy since I just changed the code to store only asterisk symbols and check the length of near numbers. But I was thinking... It's still slow. I will use an array of buckets to improve near point search, checking only 3 lines for each symbol.
@willzin-da-esfiha10 ай бұрын
Update: the buckets' version work almost instantaneously
@DiegoCattaneo10 ай бұрын
I came out with a very similar code.. but mine isn't working 😂. I'll try your code with my input. Thanks
@bigupbig219810 ай бұрын
I feel so dumb I did day 1,2 but had no idea how to do this day. Had to cheat and look up the answer
@NicolastheThird-h6m10 ай бұрын
No problem we are here to learn. This isn't cheating as long as you get what he is doing
@TheFrogfather110 ай бұрын
I made a total mess of part two to the point where 'git reset --hard' was the best option. Got there eventually but not an elegant solution at all. The feeling amongst work colleagues is that the puzzles seem a bit harder this year. Let's see how it goes...