I was able to build most of this and do part one very quickly, but for part 2 I had incorrectly assumed that the spelled out digits were not allowed to overlap which took me waaay to long to figure out that that assumption was incorrect.
Tried Roc for advent of code and immediately hit a compiler/runtime bug in part 2, where it mutates some shared memory I think in combination with tail recursion? :cry: That's what I get for thinking I don't need to know all the List.walk invocations :big_smile:
https://gitlab.com/AsbjornOlling/aoc2023
Here is mine... I spent longer with this than I will ever admit.
Mostly just getting familiar with roc stuff, I suppose. The algorithm I came up with worked as soon as I could figure out what symbols to type in what order :sweat_smile:
It's way more verbose than it needs to be, but hey.
Now I'm gonna go look over it and try and make it small and pretty and readable.
Also this was the first time I wrote more than 5 lines of roc code.
Roc feels pretty comfy so far. I got some weird errors along the way, but eh once I reformulated myself a bit and double-checked my types, stuff started working again.
I struggled a bit getting dbg to work - turns out I just needed to update basic-cli to 0.7.0
Tried Roc for advent of code and immediately hit a compiler/runtime bug in part 2, where it mutates some shared memory I think in combination with tail recursion? :cry: That's what I get for thinking I don't need to know all the List.walk invocations :big_smile:
Any chance you have or can make a repro? That seems like a pretty major bug that I'm sure many people here would love to look into.
I tested some of the solutions in my platform to test for speed. Yours is the first one, where part2 is faster then part1 :grinning_face_with_smiling_eyes:
I'll also add to Github topics before AOC is done.
Here's My Day 1
app"hello"packages{pf:"https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br"}imports[pf.Stdout,pf.Task,"./day1-input.txt"asinput:Str]provides[main]topfmain ={}<-Stdout.line"The total sum is \(part1)"|>Task.await{}<-Stdout.line"Wait, no... it's \(part2)"|>Task.awaitTask.ok{}part1=sumNumsinput|>Num.toStrpart2=repairDocinput|>sumNums|>Num.toStrrepairDoc=\doc->#Wordsareoverlappedthroughout,e.g.twoneis21#Replacingeachwithadigit,butkeepingthefull#originalwordintacttoallowalloverlapsStr.replaceEachdoc"one""one1one"|>Str.replaceEach"two""two2two"|>Str.replaceEach"three""three3three"|>Str.replaceEach"four""four4four"|>Str.replaceEach"five""five5five"|>Str.replaceEach"six""six6six"|>Str.replaceEach"seven""seven7seven"|>Str.replaceEach"eight""eight8eight"|>Str.replaceEach"nine""nine9nine"sumNums=\doc->Str.splitdoc"\n"|>List.map\line->parseLineline|>List.sumparseLine=\line->Str.graphemesline|>List.keepOksStr.toU32|>\numList->(10*Result.withDefault(List.firstnumList)0)+(Result.withDefault(List.lastnumList)0)debug=\v->dbgvv
I thought it would be fun to use a parser for this one and put the entire solution inside the parser. That was fine for part 1, but then part 2 came along and really made it gross.
I feel like this was an unusually difficult day 1. Usually the first day is just adding up some list items, but the part where spelled out numbers could overlap felt like the kind of gotcha that shows up at least a few days in.
As a currier, I ended up really confused when e.g. solveWith : List (Str, Nat) -> List Str -> Nat said that it expected end of file at the second arrow. Not sure if there's a ticket for that, but I suppose there's some parser error handling that needs to be handled or something?
Also, because the Roc tutorial for Stdin data is on basic-cli 0.5.0 and latest basic-cli is 0.7.0, my initial "copypaste-but-update-to-latest-version" failed, as Stdin.line finally got fixed to return End instead of crashing on EOF (?). Which is what I wanted anyway, but heh, as a very new person to the language that got a bit confusing.