Skip to content

Instantly share code, notes, and snippets.

(defun ca-vectorize ()
(let* ((line (thing-at-point 'line t))
(ll (string-to-list line))
(result (make-vector (1- (length ll)) 0))) ; skip newline
(loop for c in ll
for i below (length ll)
do (unless (equal c ?\n)
(if (equal c ?\s)
(setf (elt result i) 0)
(setf (elt result i) 1))))
@Arnot
Arnot / aoc-day1.el
Last active December 1, 2017 14:38
;; The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of
;; all digits that match the next digit in the list. The list is circular, so the digit after the
;; last digit is the first digit in the list.
(defun aoc-string-to-numbers (input)
(mapcar (lambda (c) (- c ?0))
(string-to-list input)))
(defun aoc-day1-1 (input)
(let* ((in-list (aoc-string-to-numbers input))
@Arnot
Arnot / day4.el
Last active December 4, 2017 13:47
(defun aoc-day3-1 (input)
(let ((num-correct-passphrases 0))
(dolist (passphrase input)
(let ((words (split-string passphrase " ")))
(when (= (length words)
(length (delete-dups words)))
(incf num-correct-passphrases))))
num-correct-passphrases))
(defvar day4input '("nyot babgr babgr kqtu kqtu kzshonp ylyk psqk"
"iix ewj rojvbkk phrij iix zuajnk tadv givslju ewj bda"
"isjur jppvano vctnpjp ngwzdq pxqfrk mnxxes zqwgnd giqh"
"ojufqke gpd olzirc jfao cjfh rcivvw pqqpudp"
"ilgomox extiffg ylbd nqxhk lsi isl nrho yom"
"feauv scstmie qgbod enpltx jrhlxet qps lejrtxh"
"wlrxtdo tlwdxor ezg ztp uze xtmw neuga aojrixu zpt"
"wchrl pzibt nvcae wceb"
"rdwytj kxuyet bqnzlv nyntjan dyrpsn zhi kbxlj ivo"
"dab mwiz bapjpz jbzppa"
(defun aoc-day4-1 (input)
(let ((num-correct-passphrases 0))
(dolist (passphrase input)
(let ((words (split-string passphrase " ")))
(when (= (length words)
(length (delete-dups words)))
(incf num-correct-passphrases))))
num-correct-passphrases))
(defun aoc-sort-string (str)
(defun create-grid ()
(let ((grid (make-vector aoc-size 0)))
(dotimes (i aoc-size)
(setf (aref grid i) (make-vector aoc-size 0)))
(setf (aref (aref grid center)
center) 1)
grid))
(defun get-cell (x y)
(cond
(defun create-grid ()
(let ((grid (make-vector aoc-size 0)))
(dotimes (i aoc-size)
(setf (aref grid i) (make-vector aoc-size 0)))
(setf (aref (aref grid center)
center) 1)
grid))
(defun get-cell (x y)
(cond
/**
* Usage
*/
Test t = Test.create()
.withMember(42)
.withString("hello")
.withString("world")
.build();
(setq registers (make-hash-table :test 'equal))
(setq highest-value-throughout-program 0)
(defun get-lines-from-input (buffername)
(with-current-buffer buffername
(split-string (buffer-substring (point-min) (point-max)) "\n" t)))
(defun process-single-line (line)
(multiple-value-bind (destination operation amount _ source comparator threshold)
(split-string line " ")
(defstruct state (sum 0) (garbage-sum 0) (group-depth 0) in-garbage after-!)
(defun process-character (s character)
(if (state-in-garbage s)
(if (state-after-! s)
(setf (state-after-! s) nil)
;; Process stuff inside garbage
(case character
(?! (setf (state-after-! s) t))
(?> (setf (state-in-garbage s) nil))