This file contains hidden or 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
(set! *warn-on-reflection* true) | |
(set! *unchecked-math* :warn-on-boxed) | |
(defn parse-int [s] | |
(Integer/parseInt s)) | |
(defn get-coords [^long n [^long sx ^long sy] [^long ex ^long ey]] | |
(for [x (range sx (inc ex)) | |
y (range sy (inc ey))] | |
(+ (long x) (* (long n) (long y))))) |
This file contains hidden or 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 parse-int [s] | |
(Integer/parseInt s)) | |
(defn parse [inst] | |
(let [[_ cmd sx sy ex ey] (re-find #"(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)" inst) | |
sx (parse-int sx) | |
sy (parse-int sy) | |
ex (parse-int ex) | |
ey (parse-int ey)] | |
[cmd [sx sy] [ex ey]])) |
This file contains hidden or 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
import Prelude | |
import Text.Regex | |
import qualified Data.HashMap.Strict as HashMap | |
type Board = HashMap.HashMap Int (HashMap.HashMap Int Bool) | |
type Coord = (Int,Int) | |
getCoords :: Coord -> Coord -> [Coord] | |
getCoords (sx,sy) (ex,ey) = [ (x,y) | x <- [sx..ex], y <- [sy..ey] ] |
This file contains hidden or 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
#lang racket | |
(require racket/match) | |
(define (get-coords sx sy ex ey) | |
(for*/list ([x (in-range sx (+ 1 ex))] | |
[y (in-range sy (+ 1 ey))]) | |
(list x y))) | |
(define (parse s) | |
(match-let ([(list _ cmd sx sy ex ey) |
This file contains hidden or 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
(let [a5 (slurp "a5.txt") | |
lines (str/split-lines a5)] | |
(count (filter (fn [s] (and | |
(not (re-find #"ab|cd|pq|xy" s)) | |
(re-find #"(.)\1" s) | |
(>= (count (re-seq #"[aeiou]" s)) 3))) | |
lines))) |
This file contains hidden or 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
import qualified Data.Hash.MD5 as MD5 | |
main = do | |
print $ head $ [ n | n <- [0..] , (==) "000000" $ take 6 $ (MD5.md5s . MD5.Str) ("bgvyzdsv" ++ (show n)) ] |
This file contains hidden or 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.a3 | |
(:require [clojure.string :as str])) | |
(let [a3 (str//trim (slurp "a3.txt"))] | |
(count | |
(loop [cs (seq a3) p [0 0] ps #{[0 0]}] | |
(if-not (seq cs) ps | |
(let [c (first cs) | |
[x y] p | |
next (condp = c |
This file contains hidden or 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.a2 | |
(:require [clojure.string :as str])) | |
(defn parse-int [s] | |
(Integer/parseInt s)) | |
(let [text (slurp "a2.txt")] | |
(reduce + (for [line (str/split-lines text)] | |
(let [[l w h] (str/split line #"x") | |
[l w h] (map #(Integer/parseInt %) [l w h]) |
This file contains hidden or 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)] |
This file contains hidden or 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
(defun color-theme-ps-warm () | |
"A color theme based on Vim's PS Warm 2." | |
(interactive) | |
(color-theme-install | |
'(color-theme-ps-warm | |
((background-color . "#111111") | |
(background-mode . dark) | |
(border-color . "#888a85") | |
(cursor-color . "#fce94f") | |
(foreground-color . "#eeeeec") |