Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I usually do AoC in Common Lisp, but this year I'm giving Swift a chance.

It's not half bad at this kind of twiddling for being a statically typed mainstream language.

https://github.com/codr7/aoc24/tree/main/swift/Sources/aoc

This year is a tiny bit weird, I was just getting ramped up organizing the event at a new job; because I think it's very useful for devs to learn some real problem solving, as opposed to stitching frameworks.

And then I had to leave because my new boss turned out to be someone I couldn't imagine working with.

Guess it'll be just me and Emacs as usual.



Excellent! Come and join the Swift leaderboard here https://forums.swift.org/t/advent-of-code-2024 if you haven't already -- it's super interesting to compare different solutions.


dont you find all the string parsing and manipulation to be quite painful in Swift? I tried to do AoC in Swift before and that put me off a lot. I liked doing little functional one liners but a week from now the parsing burden will be too high.


I found the Scanner API (1) to be pretty handy for the more complex parsing in past years.

It’s Foundation so hopefully also on Linux/Windows, but if not there’s also one on GitHub called SwiftScanner.

1: https://developer.apple.com/documentation/foundation/scanner


I program everyday in Swift. I attempted AoC for the first time in Swift last year and gave up after about a week or so for this exact reason and switched to python for the remainder. I don't want to struggle with the awkward string API to do things other languages can do in a line.


I'm curious, any specific examples you can remember?


Nah, the String type is fine as far as basic functionality goes, I like adding my own convenience stuff in extensions.

The language has been moving pretty fast though, I have a feeling a lot of features I find useful are relatively new.


I enjoyed reading your solutions! I’m surprised how terse they are!


Lovely! I try to strive for readability first and foremost, which is a challenge in itself.


Are you writing the solutions / compiling / running all with Emacs? I wanted to try Swift this year as well but feels sort of silly spinning up XCode for this.


You can use VSCode with a swift project created with the SwiftPackageManager (SPM). I find the experience to be good, with a good LSP support. I just have to sometimes trigger the build task for it to find newly defined objects.

That is if you have nothing against using VSCode.


Yep, on Linux, or WSL to be exact, I just use the internal shell though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: