this post was submitted on 31 Oct 2023
0 points (50.0% liked)

Advent of Code

295 readers
1 users here now

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

https://adventofcode.com

founded 2 years ago
MODERATORS
0
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 

As 2023 Advent of Code is approaching fast, I thought I'd revisit my 2022 entries, and I realised a good focus would be to post one a day during November. No guarantees as to the quality of the algorithms used, but hopefully people will find the code readable and interesting. If anyone has questions or ideas for improvement, I'd love to hear them.

They were all written in Dart, and I will modify each one to allow it to run online in the browser. Some of the code may look a little odd as I had to inline the functionality from some libraries that I used as DartPad doesn't support them all.

Anyway, here's the core of my response to Day 1. The full code can be read and run by following the link above.

int part1(String lines) => totalCalories(lines).first;
int part2(String lines) => totalCalories(lines).take(3).sum;

Iterable totalCalories(String lines) => lines
    .split('\n\n')
    .map((e) => e.split('\n').map(int.parse).sum)
    .sorted(descending);
no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here