Last active
December 2, 2018 12:21
-
-
Save kepi74/2528a845306514071b92f94537237263 to your computer and use it in GitHub Desktop.
Advent of Code 2018 day 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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