This file contains 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 *input* | |
(uiop:read-file-string "day3.txt")) | |
(defun eval-muls (blob) | |
(let ((sum 0)) | |
(ppcre:do-register-groups ((#'parse-integer i) (#'parse-integer j)) | |
("mul\\(([0-9]+),([0-9]+)\\)" blob sum) | |
(incf sum (* i j))))) | |
(defun eval-muls* (blob) |
This file contains 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 safep (levels) | |
(loop for (a b) on levels by #'cdr | |
with sign = (signum (- (cadr levels) (car levels))) | |
do | |
(if (null b) | |
(return t) | |
(let ((delta (- b a))) | |
(unless (and (= sign (signum delta)) | |
(<= 1 (abs delta) 3)) | |
(return nil)))))) |
This file contains 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
;; In this population, a should be selected with frequency of 10%, while | |
;; b and c are each chosen with frequency 45%. | |
(defvar weights '(10 45 45)) | |
(defvar population '(a b c)) | |
(defun cumulative-weights (weights) | |
"Return the total of `weights' and the cumulative distribution | |
table." | |
(loop for w in weights | |
sum w into total |
This file contains 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 random-0-to-1 (&optional range) | |
"Generate a random value in [0.0, 1.0)." | |
(let ((range (or range most-positive-fixnum))) | |
(/ (random range) (float range)))) |
This file contains 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
(ql:quickload :str) | |
(ql:quickload :alexandria) | |
(import 'alexandria:compose) | |
(ql:quickload :arrows) | |
(use-package :arrows) | |
(defun split-names (s) | |
(mapcar (compose #'str:downcase #'str:trim) (str:split #\, s))) | |
(let (names) |
This file contains 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
(ql:quickload :jsown) | |
(ql:quickload :dexador) | |
(ql:quickload :quri) | |
(if (evenp | |
(sxhash | |
(car (jsown:val | |
(jsown:parse | |
(dex:get | |
(quri:make-uri |
This file contains 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 pending_release {} | |
set pressed false | |
proc press_action {} { puts "pressed" } | |
proc release_action {} { puts "released" } | |
proc is_pressed {} { | |
global pressed | |
return $pressed | |
} |
This file contains 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
(ql:quickload :dexador) | |
(ql:quickload :jsown) | |
(ql:quickload :arrows) | |
(use-package :arrows) | |
(defparameter url "https://api.weather.gov/gridpoints/FWD/95,141/forecast") | |
(defun json-val-in (o &rest keys) | |
(reduce (lambda (o k) (jsown:val o k)) keys :initial-value o)) |
This file contains 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
(flet ((cycle (list) (setf (cdr (last list)) list))) | |
(let ((fcyc (cycle (list "" "" "Fizz"))) | |
(bcyc (cycle (list "" "" "" "" "Buzz")))) | |
(mapcar (lambda (f b n &aux (fb (concatenate 'string f b))) | |
(if (= 0 (length fb)) n fb)) | |
fcyc bcyc (loop for n from 1 to 100 collect n)))) |
This file contains 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 make-chain-table (&rest tables) | |
(lambda (key) | |
(labels ((aux (tables) | |
(if (null tables) | |
(values nil nil) | |
(multiple-value-bind (value found) (gethash key (car tables)) | |
(if found | |
(values value t) | |
(aux (cdr tables))))))) | |
(aux tables)))) |
NewerOlder