Last active
December 15, 2015 23:06
-
-
Save sbenhaim/af5d81a6e7bd1612aa37 to your computer and use it in GitHub Desktop.
Advent of Code: 1
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 advent.a1 | |
(:require [clojure.string :as str])) | |
(let [a1 (slurp "a1.txt")] | |
(- (count (re-seq #"\(" a1)) | |
(count (re-seq #"\)" a1)))) | |
(loop [chars (str/trim (slurp "a1.txt")) v 0 p 0] | |
(if (= -1 v) p | |
(let [c (first chars)] | |
(recur (rest chars) | |
(condp = c | |
\( (inc v) | |
\) (dec v)) | |
(inc p))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment