Hello! I'm sorry if this is the wrong forum to start a thread like this, but I am new to Clojure/lisps in general and thought I would take this year's Advent of Code (2022) as an opportunity to challenge myself to learn a bit.
So I've started Day 1 and solved the problem (in essence, Given a long list of double space separated numbers, find the largest sum amongst them) but with what looks like the most inelegant thrashing of how one might approach the problem in Clojure.
For example, the answer for the following would be 300
10
20
100
200
My solution is as follows, and I am wondering primarily:
- Is this a reasonable approach to the problem, as a beginner, what am I missing out on that would be more elegant.
- How does one even format a line like this?
(Spoiler below, in case anyone else is interested in the challenge)
(require '[clojure.string :as str])
(reduce max (map (fn [x] (reduce + (map #(Integer/parseInt %) (str/split x #"\n")))) (str/split (slurp "./input-1.txt") #"\n\n")))
I'm hoping, time permitting, to be able to continue this journey through the month so hopefully I'm able to as the challenges do become quite complicated even for languages I'm familiar with, but I can already say the REPL is really a wonderful thing.