Last active
February 15, 2017 14:04
-
-
Save allanberger/d2673f9d0842f7e19f649d9b616497de to your computer and use it in GitHub Desktop.
Advent of Code 2016 - Day 1 - Clojure
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
(ns adventofcode.days.day1 | |
(:require [clojure.string :as str])) | |
(def input1 "R3, R1, R4, L4, R3, R1, R1, L3, L5, L5, L3, R1, R4, L2, L1, R3, L3, R2, R1, R1, L5, L2, L1, R2, L4, R1, L2, L4, R2, R2, L2, L4, L3, R1, R4, R3, L1, R1, L5, R4, L2, R185, L2, R4, R49, L3, L4, R5, R1, R1, L1, L1, R2, L1, L4, R4, R5, R4, L3, L5, R1, R71, L1, R1, R186, L5, L2, R5, R4, R1, L5, L2, R3, R2, R5, R5, R4, R1, R4, R2, L1, R4, L1, L4, L5, L4, R4, R5, R1, L2, L4, L1, L5, L3, L5, R2, L5, R4, L4, R3, R3, R1, R4, L1, L2, R2, L1, R4, R2, R2, R5, R2, R5, L1, R1, L4, R5, R4, R2, R4, L5, R3, R2, R5, R3, L3, L5, L4, L3, L2, L2, R3, R2, L1, L1, L5, R1, L3, R3, R4, R5, L3, L5, R1, L3, L5, L5, L2, R1, L3, L1, L3, R4, L1, R3, L2, L2, R3, R3, R4, R4, R1, L4, R1, L5") | |
(def input2 "R2, L3") | |
(def input3 "R2, R2, R2") | |
(def input4 "R5, L5, R5, R3") | |
(defn parse-step [step] | |
[(first step) (Integer/parseInt (apply str (rest step)))]) | |
(parse-step "R4") | |
(defn parse-input [input] | |
(as-> input data | |
(str/split data #", ") | |
(map parse-step data))) | |
(parse-input input4) | |
{:n [ 0 1] | |
:e [ 1 0] | |
:s [ 0 -1] | |
:w [-1 0]} | |
(defn positions [data] | |
(->> (parse-input data) | |
(map (fn [x] ((get {\L dec \R inc} (first x)) 0))))) | |
(positions input4) | |
((get {\L inc \R dec} \R) 0) | |
; (->> (map first data))) | |
(repeat 5 [0 1]) | |
(map #(mod % 4) (reductions + (positions input4))) | |
(defn solve [input] | |
(->> input | |
parse-input | |
positions)) | |
; (solve input1) | |
; (solve input2) | |
; (solve input3) | |
; (solve input4) | |
; #_(->> input | |
; parse-input) | |
(defn transform [person] | |
(update (assoc person :hair-color :gray) :age inc)) | |
(transform {:name "Socrates", :age 39}) |
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
R3, L5, R2, L1, L2, R5, L2, R2, L2, L2, L1, R2, L2, R4, R4, R1, L2, L3, R3, L1, R2, L2, L4, R4, R5, L3, R3, L3, L3, R4, R5, L3, R3, L5, L1, L2, R2, L1, R3, R1, L1, R187, L1, R2, R47, L5, L1, L2, R4, R3, L3, R3, R4, R1, R3, L1, L4, L1, R2, L1, R4, R5, L1, R77, L5, L4, R3, L2, R4, R5, R5, L2, L2, R2, R5, L2, R194, R5, L2, R4, L5, L4, L2, R5, L3, L2, L5, R5, R2, L3, R3, R1, L4, R2, L1, R5, L1, R5, L1, L1, R3, L1, R5, R2, R5, R5, L4, L5, L5, L5, R3, L2, L5, L4, R3, R1, R1, R4, L2, L4, R5, R5, R4, L2, L2, R5, R5, L5, L2, R4, R4, L4, R1, L3, R1, L1, L1, L1, L4, R5, R4, L4, L4, R5, R3, L2, L2, R3, R1, R4, L3, R1, L4, R3, L3, L2, R2, R2, R2, L1, L4, R3, R2, R2, L3, R2, L3, L2, R4, L2, R3, L4, R5, R4, R1, R5, R3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment