Skip to content

Instantly share code, notes, and snippets.

Per Persson md2perpe

Block or report user

Report or block md2perpe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View load_graph1.py
def load_graph():
g = {}
with open('sample.txt', 'r') as f:
for line in filter(lambda l: l != '\n', f):
row = line.split('\t')
g[int(row[1])] = list(map(int, row[2:]))
return g
View index.html
<!doctype html>
<body>
<style>
td.selected {
background: red;
}
</style>
<script>
const N = 100;
const ROWS = N;
@md2perpe
md2perpe / pretty_print.py
Last active Oct 15, 2018
Pretty print av polynom
View pretty_print.py
# https://www.facebook.com/photo.php?fbid=10155461108530633&set=p.10155461108530633&type=3&theater&ifg=1
def prettyPrint(lista):
# Funktionen tar en lista med koefficienter
# till ett polynom i avtagande ordning och
# skriver ut polynomet
# Polynomets gradtal
polynomets_gradtal = len(lista) - 1
@md2perpe
md2perpe / calculate-e.py
Created Sep 23, 2018
Calculate Euler's number
View calculate-e.py
from math import factorial
e = 0
for k in range(0, 20):
e += 1/factorial(k)
print("k=% 3d: e=%.16f" % (k, e,))
@md2perpe
md2perpe / calculate-e.py
Last active Sep 23, 2018
Calculate Eulers number (e)
View calculate-e.py
# https://www.facebook.com/groups/progfml/permalink/344454616128233/
from math import factorial
e=0
n=0
step_length=1
e_right=2.71828
margin_of_error=0.001
Klart=False
View sequence.hs
toSwedish :: Integer -> String
toSwedish 1 = "ett"
toSwedish 2 = "två"
toSwedish 3 = "tre"
toSwedish 4 = "fyra"
toSwedish 5 = "fem"
toSwedish 6 = "sex"
toSwedish 7 = "sju"
toSwedish 8 = "åtta"
toSwedish 9 = "nio"
@md2perpe
md2perpe / lambda.ts
Created Jun 13, 2018
Lambda calculus in Typescript
View lambda.ts
type _bool<X, Y> = (X, Y) => X | Y;
let _true = <X, Y>(x: X, y: Y) => x;
let _false = <X, Y>(x: X, y: Y) => y;
let _not = <X, Y>(b: _bool<Y, X>) => (x: X, y: Y) => b(y, x);
let _and = <X, Y>(b1: _bool<X | Y, Y>, b2: _bool<X, Y>) => (x: X, y: Y) => b1(b2(x, y), _false(x, y));
let _or = <X, Y>(b1: _bool<X, X | Y>, b2: _bool<X, Y>) => (x: X, y: Y) => b1(_true(x, y), b2(x, y));
// Using
// let __compose = <X, Y, U, V, W>(f: (U, V) => W, g: (X, Y) => U, h: (X, Y) => V) => (x: X, y: Y) => f(g(x, y), h(x, y));
@md2perpe
md2perpe / monad.ts
Created May 25, 2018
Monad example in Typescript
View monad.ts
/////////////////////////////////////////////////////////
// Origin: https://www.youtube.com/watch?v=t1e8gqXLbsU
// Rewritten to Typescript by md2perpe on 25 May 2018
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// The interface of a monad
/////////////////////////////////////////////////////////
@md2perpe
md2perpe / sierpinski.py
Created May 12, 2018
Sierpinsky triangle in Python turtle graphics
View sierpinski.py
# https://trinket.io/python
import turtle
L = 200
turtle.speed(1000)
turtle.penup()
turtle.goto(-100, -100)
turtle.color("red")
View matching_positions.py
def matching_positions(data, choices):
# Example: data="apabanan", choices="aan"
# Initialize a dictionary for all positions of the char's in choices
positions = {}
for c in choices:
positions[c] = []
# Populate the dictionary
for k, c in enumerate(data):
You can’t perform that action at this time.