Skip to content

Instantly share code, notes, and snippets.

@sbenhaim
Last active December 15, 2015 23:06
Show Gist options
  • Save sbenhaim/af5d81a6e7bd1612aa37 to your computer and use it in GitHub Desktop.
Save sbenhaim/af5d81a6e7bd1612aa37 to your computer and use it in GitHub Desktop.
Advent of Code: 1
(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