I’m doing #AdventOfCode2022 for the first time after seeing tweets about it!
Also doing Swift solutions, so please take a look and criticise my code! It’s been a while since doing leetcode etc.
github.com/maxxfrazer/Adv
Conversation
Day 1 is complete! Ended up doing a couple of solutions. One with a straightforward approach and the other with a more complex one. Aiming to be more optimised; perfect for technical interviews. (Imperfect for everyday coding.)
2
Added Day 2 of #AdventOfCode in Swift!
Finding outcomes of Rock, Paper, Scissors here is done with ascii chars and offsets from each other for both parts, O(n):
1
1
2
#AdventOfCode Day 3 with #Swift done.
I’m using the Set class’s contains and intersection methods, which should give an okay time complexity.
To enhance, use a hash-map giving faster lookup. but i’m not adding that today as it’s the weekend!! 😅
1
2
#AdventOfCode Day 4 done.
Look at it as just a start and an end, defining conditions that meet if they overlap and contain each other.
I actually made a class for this one rather than a monstrous block of code accessing indices of indices of arrays 😅
1
1
2
Day 5 of #AdventOfCode done!
The clue is in the name, use Stacks. There’s no builtin stack class in Swift, so I implemented a basic one there.
For part 2, you can just use a temporary stack to store the items being moved.
3
Day 6 of #AdventOfCode is a sliding door problem to me.
A pointer at the start and end of the current word, find the largest word with no repeated chars up to the assigned values (4 and 14). Move the start pointer up until no char repeats!
1
1
Day 7 #AdventOfCode in Swift!
Parsing the text in this one was a bit of a pain. Splitting by “$ “ and then by the first new line was a pretty helpful hack though.
1
1
1
The best solution for day 8 of #AdventOfCode would be a dynamic programming one I think (🤢).
There’s for sure a better choice than what I’ve done, but am trying to avoid a complete brute force/naive solution with this answer:
Replying to
I haven’t seen a problem like this one before, I liked it!
In #AdventOfCode Day 9 you’re crossing a bridge and there’s a rope flailing around, so calculate where the end of the rope will be based on the front of the rope’s movements. #AdventOfSwift
1
