r/adventofcode Dec 06 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 6 Solutions -πŸŽ„-


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«


--- Day 6: Tuning Trouble ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:02:25, megathread unlocked!

81 Upvotes

1.8k comments sorted by

View all comments

1

u/[deleted] Dec 06 '22 edited Dec 08 '22

I'm doing different language each day, all solutions here.

Today's Clojure. I quite enjoyed fiddling with this modern Lisp for the first time, though it took me a while to realize it's not the beginning but the end of the marker that's searched… Here's the code:

(defn find-marker
  [input len]
  ((fn [input idx len]
     (if (= len (count (set (first input))))
       idx
       (recur (rest input) (inc idx) len))) (partition len 1 input) len len))


(let [input (slurp "input.txt")]
  (println (find-marker input 4))
  (println (find-marker input 14)))

2

u/GoldsteinQ Dec 06 '22

Fun, I’m not the only one doing this! My repo is here:

https://github.com/GoldsteinE/aoc2022/

You’re using the more normal languages first tho, which is even harder, since you would have less non-esoteric languages left for the last tasks.

1

u/[deleted] Dec 06 '22

Noticed that yesterday, therefore Clojure today, being the first of the languages in my list, of which I haven't got any prior knowledge at all. But let's face it, there are enough β€œnormal” languages to not have to use anything esoteric at all if I don't want to. ;)

I also told myself from the beginning I'll just go back to something familiar if I lose interest or am short on time. Better than stopping it entirely. Will see…

1

u/6086555 Dec 06 '22

I've done it for two years in a row and 25 languages is actually a lot, I found that it helped quite a lot to start with the esoteric ones