Skip to content

Instantly share code, notes, and snippets.

View louisswarren's full-sized avatar

Louis Warren louisswarren

View GitHub Profile
@louisswarren
louisswarren / 28.py
Created July 16, 2019 10:06
28 hour day
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Sunday']
def time(n):
day = days[(n // 24) % 7]
n = n % 24
if n == 0:
hour = '12am'
elif n < 12:
hour = f'{n}am'
elif n == 12:
@louisswarren
louisswarren / disease.py
Created July 15, 2019 11:37
Basic disease modelling in python
from random import random, sample
import networkx as NX
import numpy as NP
from matplotlib import pyplot as MPL
class Graph:
def __init__(self, vertices, edges):
self.vertices = vertices
self.edges = edges
@louisswarren
louisswarren / arrow.agda
Created July 2, 2019 11:05
Decidability for the implicational fragment in Agda
module Logic (X : Set) where
open import Decidable
open import List
--infixr 5 _++_
--_++_ : {A : Set} → List A → List A → List A
--[] ++ ys = ys
--(x ∷ xs) ++ ys = x ∷ xs ++ ys
@louisswarren
louisswarren / logging.py
Last active June 25, 2019 09:47
Logging in python, because mutable default arguments is a feature
def log(x=None, acc=[]):
if x is None:
print('\n'.join(acc))
else:
acc.append(x)
log("Hello")
log("Goodbye")
log()
@louisswarren
louisswarren / implicational.py
Last active June 15, 2019 10:36
Decidability algorithm for the implicational fragment of minimal logic
# Simple implementation of proving/disproving implicational statements
from collections import namedtuple
# String constants
lBOT = '⊥'
lNEG = '¬'
lIMP = ' → '
lMMP = ' ⇒ '
@louisswarren
louisswarren / siso.py
Created June 10, 2019 10:35
Python co-routine to store a single value
from collections import namedtuple
Arrow = namedtuple('Arrow', 'tail head')
# Single input single output
def siso():
def inner():
x = yield
yield
yield x
@louisswarren
louisswarren / possum.py
Last active May 28, 2019 03:58
Simulate possums meeting on random walks in python
import random
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
@louisswarren
louisswarren / lagdastrip.py
Last active June 1, 2019 05:39
Strip literate agda down to agda
#!/usr/bin/env python3
import sys
def get_code_lines(lines):
in_code = False
for line in lines:
if line.startswith(r'\begin{code}'):
in_code = True
yield '--STRIP: '
@louisswarren
louisswarren / Colour.agda
Last active May 11, 2019 09:05
Ray tracing in Agda
open import Agda.Builtin.Float
record Colour : Set where
constructor colour
field
r g b : Float
@louisswarren
louisswarren / strange.agda
Last active April 16, 2019 00:19
Surprising behaviour
data ⊥ : Set where
hmm : ∀ α → ⊥
-- Agda infers that
-- α : ⊥
-- because that's only way this could be provable?
hmm α = α