Skip to content

Instantly share code, notes, and snippets.

(ns bike-bingo
(:require
;; We'll use cl-format to draw the board.
[clojure.contrib.pprint :as pp]))
;; Here's our 5x5 bingo board. We're counting horizontal, vertical,
;; diagonal, four corners, and blackout. The numbers in each square
;; represent how many bingos that square is involved in (excluding
;; blackout).
;;
;; The Common Lisp library for Emacs Lisp gives us keyword arguments
;; for defun*
(require 'cl)
(defvar projects (list) "This keeps track of all available projects.")
(defvar project (list) "And here's our current project.")
(defvar project-index (list) "This will store the project index of files.")
(defvar project-default-filetypes
'("*.el" "*.rb" "*.py" "*.rb" "*.clj" "*.php" "*.js" "*.html")
"Files for indexing.")
@sbenhaim
sbenhaim / color-theme-ps-warm.el
Created December 29, 2010 20:08
A color theme for Emacs.
(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")
@sbenhaim
sbenhaim / advent-1.clj
Last active December 15, 2015 23:06
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)]
@sbenhaim
sbenhaim / advent-2.clj
Last active December 16, 2015 02:54
Advent of Code: 2
(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])
@sbenhaim
sbenhaim / advent-3.clj
Last active December 16, 2015 03:01
Advent of Code: 3
(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
@sbenhaim
sbenhaim / advent-4.hs
Last active December 16, 2015 03:27
Advent of Code: 4
import qualified Data.Hash.MD5 as MD5
main = do
print $ head $ [ n | n <- [0..] , (==) "000000" $ take 6 $ (MD5.md5s . MD5.Str) ("bgvyzdsv" ++ (show n)) ]
@sbenhaim
sbenhaim / advent-5.clj
Created December 12, 2015 03:45
Advent of Code: 5
(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)))
#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)
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] ]