- 33 Posts
- 19 Comments
For entertainment purposes only, I’ll be trying a solution in Uiua each day until it all gets too much for me…
$ 4 3 $ 2 5 $ 1 3 $ 3 9 $ 3 3 ⊜∘⊸≠@\n # Partition at \n. ⊜(⍆∵⋕)⊸≠@\s # Partition at space, parse ints, sort. /+/(⌵-) # Get abs differences, sum.
It’s normally not so tricky on the first day, and the examples also normally do a much better job of guiding you away from wrong approaches so the increasing delay is intended to ensure you aren’t just spamming poorly tested answers.
The task in part two could be better written as “find the first occurrence of a digit in the string (either as a digit or as a word), and then separately find the last occurrence of a digit (either as a digit or as a word again) then compose these two digits”. Thinking of it like that should help you identify where your problem lies.
Dart solution
Here’s my solution to start the ball rolling. In the end I incorporated my part 1 answer into the part 2 logic, and golfed the code quite a lot.
import 'package:collection/collection.dart'; var ds = '0123456789'.split(''); var wds = 'one two three four five six seven eight nine'.split(' '); int s2d(String s) => s.length == 1 ? int.parse(s) : wds.indexOf(s) + 1; int value(String s, List digits) { var firsts = {for (var e in digits) s.indexOf(e): e}..remove(-1); var lasts = {for (var e in digits) s.lastIndexOf(e): e}..remove(-1); return s2d(firsts[firsts.keys.min]) * 10 + s2d(lasts[lasts.keys.max]); } part1(List lines) => lines.map((e) => value(e, ds)).sum; part2(List lines) => lines.map((e) => value(e, ds + wds)).sum;
Not sure what caused the downvotes here? Did the solution not work on some test data? Or did people hate the idea of me having more free time?
mykl@lemmy.worldto
Technology@lemmy.world•Patient privacy fears as US spy tech firm Palantir wins £330m NHS contractEnglish
9·2 years agohe likes to larp in the words of a better man
That’s such a great description of this kind of tech-bro behaviour.
That’s probably going to be a bit much for me to get my head around any time soon, but it actually inspired me to complete the automation around my own solutions :-)
Haha, I bit the bullet and installed Clojure… and Calva… and Leiningrad… and eventually got it to run locally. Looks like it’s quite slow via the REPL, but I get similar times to you when I run it with plain old "clojure -M”. That looks like a nice REPL though. I might pick through your code a bit more and see if I can improve my solution before Sunday!
Thanks, I’m not that familiar with Clojure, but I can read it okay. How fast did that run for you? I tried it in an online Clojure editor and it took more than 10 seconds for me, which from memory is comparable with my solution before I started hacking in some terrible shortcuts…
mykl@lemmy.worldMtoAdvent of Code@lemmy.world•What is Nadvent of code how do I get it?
21·2 years agoHaha, “Nadvent of Code” was just a joke description for my revisiting of last year’s challenges. It stands for “Not Advent of Code” or “November Advent of Code” depending on how the mood takes me. There’s a link to last year’s overview page on each post, and to the specific day on my more recent posts. Or you can just look at my solutions and figure out how you’d rewrite them in Rust. Have fun.
I first started going through my solutions from last year because I was intrigued by the interesting new language Uiua (pronounced wee-wuh) which is described as a “general purpose, stack-based, array-oriented programming language with a focus on simplicity, beauty, and tacit code.” (think APL meets FORTH!) But I soon realised that although I could solve some of the problems in Uiua, for others I don’t think a day will be long enough!
So it will be back to Dart this year with the goal of having every solution runnable in DartPad in well under one second, and ideally without having to search for hints online. I made it to day 19 last year before I got stumped; you’ll see more about that on Sunday!
mykl@lemmy.worldOPto
Programming@programming.dev•I'm posting a daily Dart solution to last year's Advent of Code challenges
1·2 years agoTrue. I’m certainly at the point where quick jobs that I would have once done in Python quite often get done in Dart instead, avoiding the “context switch” of having to think in Python for that one task.
mykl@lemmy.worldOPto
Programming@programming.dev•I'm posting a daily Dart solution to last year's Advent of Code challenges
1·2 years agoYes, when I did a search, I found I had a choice between two quite small and inactive communities, so I went for the slightly larger one. I’ll crosspost today’s post to that community see if it stirs up any more interest.
mykl@lemmy.worldOPto
Programming@programming.dev•I'm posting a daily Dart solution to last year's Advent of Code challenges
3·2 years agoYes, I really adopted it due to Flutter, but the dev team really are doing great work to make it a nice language, especially with version 3.
mykl@lemmy.worldto
Technology@lemmy.world•Results of the "Can you tell which images are AI generated?" surveyEnglish
3·2 years agoOof. I got about 65% on the images I hadn’t seen in the post. I must be pretty close to being replaceable by an adversarial network.
mykl@lemmy.worldMto
What is this thing?@lemmy.world•Found this on my toe after swimming in a lake [Solved: Leech]English
1·3 years agoLooks like it 🙁. If you can bear to open this post again could you edit the title to add [SOLVED]? Thanks!
mykl@lemmy.worldMto
What is this thing?@lemmy.world•hole at the entrance of house [SOLVED]English
1·3 years agoHi OP, if you’re happy with the answers you’ve got here, could you edit your post to add [SOLVED] to the end of the title? Many thanks!
mykl@lemmy.worldMto
What is this thing?@lemmy.world•hole at the entrance of house [SOLVED]English
4·3 years agoYep, “boot-scraper” 😀
mykl@lemmy.worldMto
What is this thing?@lemmy.world•Found this in Myrtle Beach. It looked like a shiny black rock when wet, but now I'm not so sure. Is this a fossil, or something a lot less interesting?English
1·3 years agoHi OP, I thought would be a great question for the newly created Geology group, so I posted a link to it there and got this great answer – in short:
There are many small fossils on that rock. It would be hard to tell what the rock itself is from just the photo. Limestone is the most likely candidate.
Go and read the full answer for more details!
If you’re happy with the answers you’ve got could you edit your title to add [SOLVED] at the end? Thanks, Michael


I’m more like the sorcerer’s apprentice watching my arrays get increasingly out of my control :-)