Skip to content

Instantly share code, notes, and snippets.

View christophejunke's full-sized avatar

chris christophejunke

  • France
  • 19:29 (UTC +02:00)
View GitHub Profile
@christophejunke
christophejunke / day-10.lisp
Last active December 10, 2019 11:42
AoC 2019 Day 10
(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
@christophejunke
christophejunke / day-03-alt.lisp
Last active December 4, 2019 17:44
day-03-alt.lisp
(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)
(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)))))
(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)))
(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))
@christophejunke
christophejunke / fizzbuzz.pl
Last active December 31, 2018 21:32
FizzBuzz alternative
% 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
#include <stdio.h>
#include <stdbool.h>
int main (void)
{
/* PARAMETERS */
/* Upper bound of loop (inclusive) */
const unsigned int upper_bound = 12;