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
Replying to
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
I apologise form my horrendous method of turning the text file into objects in the above solution. Xcode likes to force a newline at the end and trim whitespace chars at the end of lines, so I had to work around that rather than exclusively open the file with another editor…
1
