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
from automathon import DFA | |
from collections import defaultdict | |
from itertools import zip_longest | |
from math import floor | |
from random import randint | |
# See https://www21.in.tum.de/teaching/sar/SS20/9.pdf | |
def ineq_to_dfa(A: list[int], b: int) -> DFA: | |
n = len(A) |
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
-- Chocolate Bar Theorem 🍫, as illustrated in https://www.instagram.com/p/CzGr1yfAHFB/ | |
-- Credits: https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/Formulating.20the.20chocolate.20bar.20theorem | |
-- Run on https://live.lean-lang.org/ | |
import Mathlib.Data.Nat.Basic | |
inductive ChocoTablet : Nat -> Nat -> Type where | |
| square : ChocoTablet 1 1 | |
| hJoin {a b b' : Nat} : ChocoTablet a b -> ChocoTablet a b' -> ChocoTablet a (b + b') |
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
from typing import Iterator | |
HereditaryRepresentation = list[tuple[int, "HereditaryRepresentation"]] | |
def to_base(n: int, base: int, prefix: bool = False) -> list[int]: | |
""" | |
Computes the representation of n in the specified base. | |
""" | |
if n == 0: |
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
// See lipsum.dev | |
import React, { useEffect, useRef, useState } from "react"; | |
const L = 8; | |
function baseFunc(u, v) { | |
return (x, y) => | |
Math.cos(((2 * x + 1) * u * Math.PI) / 16) * | |
Math.cos(((2 * y + 1) * v * Math.PI) / 16); |
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
# See https://mitpress.mit.edu/9780262046305/introduction-to-algorithms/, chapter 30 | |
# /!\ Do not use it in production /!\ | |
from math import e, pi | |
import numpy as np | |
from numpy.testing import assert_array_equal | |
def fft(L, sign=-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
# Part of https://lipsum.dev/2021-06-1-miller-rabin-openssl/ | |
# /!\ Warning /!\ — Not safe for real cryptographic usage | |
from collections import Counter | |
from random import randrange | |
import statistics | |
# Fermat | |
def fermat_test(n, max_witness=100): |
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
// RotatingCube React component, used in https://lipsum.dev/2020-09-1-rotations/ | |
import * as BABYLON from 'babylonjs' | |
import * as GUI from 'babylonjs-gui' | |
import React, { useEffect, useRef, useState } from 'react' | |
const canvasWidth = 500; | |
const canvasHeight = 300; | |
function initScene(canvas, rotationCb) { | |
const engine = new BABYLON.Engine(canvas); |
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
# See https://lipsum.dev/2020-05-1-pourquoi-les-polynomes/ | |
from numbers import Number | |
class Polynomial: | |
def __init__(self, *coefficients): | |
self.degree = -1 | |
self.coefficients = tuple(coefficients) | |
for i, coef in enumerate(self.coefficients): | |
if coef != 0: |