Skip to content

Instantly share code, notes, and snippets.

View lispandfound's full-sized avatar
🕶️
Vibing

Jake Faulkner lispandfound

🕶️
Vibing
  • QuakeCoRE
  • Christchurch, New Zealand
  • 17:29 (UTC +12:00)
View GitHub Profile
import sys
def max_span(graph, permutation):
''' Calculate the maximum span of a permutation. '''
# O(n^2) calculate max span
max_span = 0
for i in range(len(permutation)):
for j in range(i + 1, len(permutation)):
span = j - i
@lispandfound
lispandfound / duplicates.py
Last active December 30, 2017 08:56
duplicates.py
from __future__ import print_function
import sys
import os
import subprocess
def get_output(command):
return subprocess.check_output(command, shell=True)
def find_duplicates(directory):
@lispandfound
lispandfound / hanoi.py
Created April 16, 2018 10:47
Towers of Hanoi Cairo Background
import itertools
import cairo
def interpret_state(disks, counter):
''' Return the position of the towers of hanoi after `counter` moves.
Efficient algorithm, runs in O(k) time, k being the number of disks.
@lispandfound
lispandfound / island.py
Created April 24, 2018 07:42
Island Capacity
def find_capacity(sequence):
''' Return the capacity of a height map.
Here the "capacity" of a height is represented by filling a height
map with water such that it does not spill over.
Consider a simple height map [2, 1, 0, 1, 2, 3]:
.....#
#...##
##.###
@lispandfound
lispandfound / giftwrap.hs
Last active April 29, 2018 03:01
Gift Wrap Implementation
-- For the minimumBy function
import Data.List
type Point = (Float, Float)
-- Returns the relation between a line segment and a point. Takes three
-- arguments, the first two defining the line segment, The last a test
-- point. The value is 0 if the test point is on the line >0 if it is
-- to the right and <0 if it is to the left.
lineRelation :: Point -> Point -> Point -> Float
lineRelation (x1, y1) (x2, y2) (x, y) = (y - y1) * (x2 - x1) - (y2 - y1) * (x - x1)
-- load standard vis module, providing parts of the Lua API
require('vis')
require('surround')
require('vis-commentary')
vis.events.subscribe(vis.events.INIT, function()
-- Your global configuration options
vis:command('set theme default-16')
vis:command('set ai on')
vis:command('set expandtab true')
color cursor black white
color status white default bold
color header black white
color title-blur white black
color title-focus white black bold
#!/usr/bin/env fish
set -l maths (cat)
echo 'stem:[' (string trim -- "$maths" ) ']'
asciiTeX "$maths"
import Data.Foldable
import qualified Data.List as L
data Tree a = Node Integer (Tree a) (Tree a) a | Leaf deriving (Show, Eq)
data Path = LeftP | RightP
instance Foldable Tree where
foldMap f Leaf = mempty
foldMap f (Node _ l r v) = foldMap f l `mappend` f v `mappend` foldMap f r
import Data.Foldable
import qualified Data.List as L
data Tree a = Node Integer (Tree a) (Tree a) a | Leaf deriving (Show, Eq)
data Direction a = L Integer a (Tree a) | R Integer a (Tree a)
newtype Zipper a = (Tree a, [Direction])
left :: Zipper a -> Zipper a
left z@(Zipper Leaf directions) = z
left (Zipper (Node lvl left right val) directions) = Zipper left $ (Left lvl val right):directions