- cross-posted to:
- lobsters@lemmy.bestiver.se
- cross-posted to:
- lobsters@lemmy.bestiver.se
Alright, show me I’m not the only one in this community, and show off some solutions!
Here’s my Day 1 solution in Factor (minus imports):
spoiler
: get-input ( -- left-list right-list )
"aoc-2024.01" "input.txt" vocab-file-lines
[ split-words harvest ] map unzip
[ [ string>number ] map ] bi@ ;
: part1 ( -- n )
get-input
[ sort ] bi@
[ - abs ] 2map-sum ;
: part2 ( -- n )
get-input
histogram
'[ dup _ at 0 or * ] map-sum ;
Sadly, Factor doesn’t get highlighted properly here, so here it is again as an image:
spoiler
I probably won’t last the week, but what solutions I do have will be up on GitHub.
Day 2:
spoiler
: get-input ( -- reports ) "aoc-2024.02" "input.txt" vocab-file-lines [ split-words [ string>number ] map ] map ; : slanted? ( report -- ? ) { [ [ > ] monotonic? ] [ [ < ] monotonic? ] } || ; : gradual? ( report -- ? ) [ - abs 1 3 between? ] monotonic? ; : safe? ( report -- ? ) { [ slanted? ] [ gradual? ] } && ; : part1 ( -- n ) get-input [ safe? ] count ; : fuzzy-reports ( report -- reports ) dup length <iota> [ remove-nth-of ] with map ; : tolerable? ( report -- ? ) { [ safe? ] [ fuzzy-reports [ safe? ] any? ] } || ; : part2 ( -- n ) get-input [ tolerable? ] count ;
Image:
spoiler