Skip to content

Instantly share code, notes, and snippets.

@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))
@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))
(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))))
(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))))
(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))))
(defun catalan-next-row (v)
(if (or (null v)
(= (length v) 0))
[1]
(let ((r (make-vector (1+ (length v)) 1)))
(dotimes (x (length v))
(unless (= x 0)
(setf (aref r x)
(+ (aref v x)
(aref r (1- x))))))
(defun my/move-to-middle ()
(interactive)
(let* ((begin (line-beginning-position))
(end (line-end-position))
(middle (+ begin (/ (- end begin) 2))))
(goto-char middle)))
(global-set-key (kbd "C-c m") 'my/move-to-middle)
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
(defun filter (&rest args) ; args = list of all arguments
(let ((factors (list -1 -1 -1
-1 8 -1
-1 -1 -1)))
(reduce '+ (mapcar* '* factors args))))
(filter 10 20 30 40 50 60 70 80 90)
;; => 0
(defun filter (&rest args) ; args = list of all arguments
(let ((factors (list -1 -1 -1
-1 8 -1
-1 -1 -1)))
(reduce '+ (map '* factors args))))