Skip to content

Instantly share code, notes, and snippets.

@commander-trashdin
commander-trashdin / combo==.lisp
Created August 24, 2024 11:44
Fucking == in CLOS method combinations
(define-method-combination eql-combinator (&optional (order ':most-specific-last))
((around (:=) :order order)
(primary (eql-combinator) :order order :required t))
(if around
`(and ,@(mapcar (lambda (method)
`(call-method ,method))
around))
`(call-method ,(first primary))))
@commander-trashdin
commander-trashdin / dfs.cpp
Created December 14, 2023 15:34
Muh DFS template
#include <vector>
#include <utility>
using Graph = std::vector<std::vector<int>>;
enum class Visited { WHITE, GREY, BLACK };
void DFSVisit(size_t start, const Graph& graph, std::vector<Visited>& colormap);
void TraverseGraphInDfsOrder(const Graph& graph) {
@commander-trashdin
commander-trashdin / fusion-sketch.lisp
Created April 15, 2023 15:46
Loop fusion for more confusion
(defclass fusion-info ()
((names :initarg :names
:initform nil
:accessor names)
(fields :initarg :fields
:initform nil
:accessor fields)
(returns :initarg :returns
:initform nil
:accessor returns)
@commander-trashdin
commander-trashdin / forth.rs
Last active March 26, 2023 21:14
Shityy Forth impl
use std::collections::HashMap;
pub type Value = i32;
pub type Result = std::result::Result<(), Error>;
type Builtin = fn(&mut Vec<Value>) -> Result;
pub struct Forth<'a> {
stack: Vec<Value>,
names: HashMap<String, &'a [&'a str]>,
builtins: HashMap<&'static str, Builtin>,
@commander-trashdin
commander-trashdin / iter.lisp
Last active December 6, 2022 09:11
Iterators, sketch
(defmacro ->> (obj &rest fns)
(labels ((rec (ls acc)
(if ls
(destructuring-bind (fst . rst) ls
(rec rst (if (listp fst)
(destructuring-bind (fn . args) fst
`(,fn ,acc ,@args))
`(,fst ,acc))))
acc)))
(rec fns obj)))
@commander-trashdin
commander-trashdin / forth.cpp
Last active October 29, 2022 22:57
My shitty forth like calc
#include <iostream>
#include <string>
#include <variant>
#include <tuple>
#include <stdexcept>
#include <sstream>
#include <vector>
enum class Op {
@commander-trashdin
commander-trashdin / day10.lisp
Created December 10, 2021 18:47
AoC 2021, day 10
(defun read-lines (path) ;; read lines just try this out
(with-open-file (stream path :direction :input :if-does-not-exist :error)
(let ((res (make-array 0 :adjustable t
:fill-pointer 0
:element-type 'string)))
(loop :for line := (read-line stream nil nil)
:while line
:do (vector-push-extend line res))
res)))
@commander-trashdin
commander-trashdin / day9.lisp
Created December 9, 2021 14:10
AoC 2021, day 9
(defun read-lines (path)
(with-open-file (stream path :direction :input :if-does-not-exist :error)
(flet ((line->vector (line)
(let ((vec (make-array 0 :adjustable t :fill-pointer 0)))
(loop :for ch :across line
:do (vector-push-extend (- (char-code ch) 48) vec))
vec)))
(let ((res (make-array 0 :adjustable t :fill-pointer 0)))
(Loop :for line := (read-line stream nil nil)
:while line
@commander-trashdin
commander-trashdin / day6.lisp
Last active December 6, 2021 19:24
AoC 2021, day 6
(defun read-cycle-num (path) ;;reading input
(flet ((convert (char)
(- (char-code char) 48)))
(with-open-file (stream path :direction :input :if-does-not-exist :error)
(let ((res (make-array 0 :adjustable t :fill-pointer 0 :element-type 'fixnum)))
(loop :for cycle := (read-char stream nil nil)
:while cycle
:do (vector-push-extend (convert cycle) res)
(read-char stream nil nil))
res))))
@commander-trashdin
commander-trashdin / day5.lisp
Last active December 5, 2021 15:08
AoC day 5, stupid solution
(defun read-coords (path)
(with-open-file (stream path :direction :input :if-does-not-exist :error)
(let ((res (make-array 0 :adjustable t :fill-pointer 0)))
(loop :for (x1 y1 _ x2 y2)
:= (uiop:split-string (read-line stream nil nil) :separator ", ")
:while x1
:do (vector-push-extend (list (parse-integer x1)
(parse-integer y1)
(parse-integer x2)
(parse-integer y2)) res))