This file contains hidden or 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
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 |
This file contains hidden or 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 __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): |
This file contains hidden or 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
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. |
This file contains hidden or 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
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]: | |
.....# | |
#...## | |
##.### |
This file contains hidden or 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
-- 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) |
This file contains hidden or 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
-- 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') |
This file contains hidden or 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
color cursor black white | |
color status white default bold | |
color header black white | |
color title-blur white black | |
color title-focus white black bold |
This file contains hidden or 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
#!/usr/bin/env fish | |
set -l maths (cat) | |
echo 'stem:[' (string trim -- "$maths" ) ']' | |
asciiTeX "$maths" |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |