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
(defpackage :advent.2019.10 (:use :cl :alexandria)) | |
(in-package :advent.2019.10) | |
;; (setf *default-pathname-defaults* #P"~/data/advent/2019/") | |
;; day 10 - part 1 | |
(defun map-map (fn stream &aux (y 0) (x 0)) | |
(flet ((callback () (funcall fn x y))) | |
(loop |
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
(defpackage :advent.2019.03-alt (:use :cl :alexandria :cl-ppcre)) | |
(in-package :advent.2019.03-alt) | |
(defstruct seg lo hi o d z) | |
(defstruct (hseg (:constructor hseg (lo hi o d z)) (:include seg))) | |
(defstruct (vseg (:constructor vseg (lo hi o d z)) (:include seg))) | |
(defun seg (type from to z) | |
(funcall type | |
(min from to) |
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-package :advent.2019) | |
(defstruct (point (:conc-name) (:constructor point (x y))) x y) | |
(defstruct (segment (:conc-name)) from to) | |
(defstruct (hsegment (:constructor hsegment (from to)) (:include segment))) | |
(defstruct (vsegment (:constructor vsegment (from to)) (:include segment))) | |
(defun manhattan (p1 p2) | |
(+ (abs (- (x p2) (x p1))) | |
(abs (- (y p2) (y p1))))) |
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
(defpackage :o (:use :cl :bricabrac.sdl2.event-loop :sdl2)) | |
(in-package :o) | |
(defgeneric handle-event (state event type) | |
(:method (state event type)) | |
(:method (state event (type (eql :quit))) | |
(throw :quit :quit))) | |
(defun clock-ms () | |
(round (* (osicat:get-monotonic-time) 1000))) |
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
(defpackage :ev (:use :cl :optima :alexandria)) | |
(in-package :ev) | |
(defstruct (meta (:constructor meta (form))) form) | |
(defun alist/augment (env namespace key value) | |
(acons namespace (acons key value (cdr (assoc namespace env))) env)) | |
(defun alist/augment* (env namespace fresh-alist) | |
(acons namespace (nconc fresh-alist (cdr (assoc namespace env))) env)) |
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
% tested with http://eclipseclp.org/ | |
divisors_term(_, [3,5],"FizzBuzz"). | |
divisors_term(_, [3], "Fizz"). | |
divisors_term(_, [5], "Buzz"). | |
divisors_term(N, [], N). | |
% first clause, always fails, but with side-effects | |
fizz_buzz :- | |
% backtrackably iterates N from 1 to 100 by 1 |
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
#include <stdio.h> | |
#include <stdbool.h> | |
int main (void) | |
{ | |
/* PARAMETERS */ | |
/* Upper bound of loop (inclusive) */ | |
const unsigned int upper_bound = 12; |
NewerOlder