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 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)))) |
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
;; 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)) |
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 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)) |
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
(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" |
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 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) |
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 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 |
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 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 |
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
/** | |
* Usage | |
*/ | |
Test t = Test.create() | |
.withMember(42) | |
.withString("hello") | |
.withString("world") | |
.build(); |
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
(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 " ") |
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
(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)) |