Skip to content

Instantly share code, notes, and snippets.

@kepi74
Last active December 2, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kepi74/2528a845306514071b92f94537237263 to your computer and use it in GitHub Desktop.
Save kepi74/2528a845306514071b92f94537237263 to your computer and use it in GitHub Desktop.
Advent of Code 2018 day 01
(defn get-final-freq
"Day one: calculate resulting frequency"
[freq_list]
(reduce + freq_list))
(defn repeated-freq
"Day one: first occur of repeated frequency"
[freq_list]
(reduce
(fn [vect freq] (
let [curr_freq (+ (last vect) freq)
new_vect (conj vect curr_freq)]
(if (some #(= curr_freq %) vect) (reduced (last new_vect)) new_vect)))
[0]
(cycle freq_list)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment