Skip to content

Instantly share code, notes, and snippets.

View benmkw's full-sized avatar

Benedikt Mandelkow benmkw

  • Germany
View GitHub Profile
@benmkw
benmkw / pratt.rs
Created April 9, 2020 16:20
pratt parser (and simple interpreter), handels both associativity and precedence
// ported from https://www.craftinginterpreters.com/compiling-expressions.html#a-pratt-parser
fn main() {
let input = "10*2+3";
assert_eq!(run(input), 10 * 2 + 3);
let input = "293474*4^5-50";
assert_eq!(run(input), 300_517_376 - 50);
let input = "-50+3*2^3";
assert_eq!(run(input), -50+3*8);
@benmkw
benmkw / main.rs
Created March 28, 2020 10:24
basic_rust_executor
// https://gcc.godbolt.org/z/dT6sd5
use std::{
future::Future,
pin::Pin,
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
fn foo() {}
@benmkw
benmkw / main.zig
Created December 29, 2019 09:33
trying to build a trie at comptime for efficient string matching
// https://gcc.godbolt.org/z/n5eApv
// https://gcc.godbolt.org/z/Lximvt shorter, remove inline -> issue
// https://gcc.godbolt.org/z/dLznz9 wip more inline
// ok https://gcc.godbolt.org/z/3mv-Z6
const std = @import("std");
const warn = std.debug.warn;
const math = std.math;
const VALUE = enum {
@benmkw
benmkw / z3_sudoku_like.py
Created December 18, 2019 20:14
at a meetup someone mentioned a game for which they wanted to generate challenges with unique solutions and i proposed to use z3 for this
# modeled after https://ericpony.github.io/z3py-tutorial/guide-examples.htm
# at a meetup someone mentioned a game for which they wanted to generate challenges with unique solutions and i proposed to use z3 for this
# the rules are similar to sudoku
# there are two symbols represented as -1 and 1 because this made calculations easier
from z3 import *
from itertools import *
import numpy as np