Skip to content

Instantly share code, notes, and snippets.

View p7g's full-sized avatar

Patrick Gingras p7g

View GitHub Profile
@p7g
p7g / 14.go
Created December 14, 2021 16:53
advent of code 2021 day 14 in golang
package main
import (
"math"
"strings"
)
const data = `
`
@p7g
p7g / aoc2021-12-computed.diff
Created December 12, 2021 16:56
the after takes less than double the time of the before
diff --git a/12.py b/12.py
index 8cb48a8..e6097ae 100644
--- a/12.py
+++ b/12.py
@@ -8,39 +8,39 @@ for line in data.splitlines():
G.add_edge(a, b)
-def find_paths(G, so_far, visited, from_="start"):
+def find_paths(G, so_far, from_="start"):
from aoc import *
# This function caches very well
@cache
def fuel_cost(diff):
return sum(range(diff + 1))
data = list(map(int, data.split(",")))
@p7g
p7g / fastconv.ts
Created October 14, 2021 01:36
the most robustest and fastest unit conversion library or your money back
type Quantity = symbol;
const Length: unique symbol = Symbol("Length quantity");
interface Unit<Q extends Quantity> {
quantity: Q;
factor: number;
}
export const Millimeter: Unit<typeof Length> = {
@p7g
p7g / nfa.py
Last active August 29, 2021 01:28
Matching a string against an NFA in Python
ε = object()
# NFA for a*ab;
#
# ε a b
# ->(0)--->(1)--->(2)--->((3))
# ^ \
# |__|
# a
#
@p7g
p7g / bench.b
Last active August 28, 2021 16:32
Rust BF interpreters, static vs dynamic dispatch
Benchmark brainf*ck program
>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
++++++++[>++++++++++[>++++++++++[>++++++++++[>+
+++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
@p7g
p7g / typesys2.py
Last active July 10, 2021 01:18
An even smaller type system in Python
# Types and type constructors
# flake8: noqa
from __future__ import annotations
class TypeConstructor:
def __init__(
self, parameters: list[TypeParameter], super_: Instance | BottomType
) -> None:
@p7g
p7g / typesys.py
Created June 12, 2021 02:17
A small type system with nominal subtyping and generics
import abc
import typing as t
class TypeError(Exception):
pass
class TypeParam:
def __init__(self, name: str, var: "TypeVar") -> None:
@p7g
p7g / mpython.rs
Created April 16, 2021 02:41
mpython
use indexmap::{IndexMap, IndexSet};
use slotmap::SlotMap;
use smol_str::SmolStr;
use std::collections::HashMap;
use std::rc::Rc;
use tinyvec::TinyVec;
fn main() {
let mut consts = ConstMap::with_key();
let mut map = IndexMap::new();
@p7g
p7g / day23part2.py
Last active March 12, 2021 04:48
cbcvm: 6.585 total, Python: 10.573 total
from itertools import count
from lib.input import fetch
def main():
class node:
__slots__ = "label", "next"
def __init__(self, label):
self.label = label