Instantly share code, notes, and snippets.

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
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,))
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"
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));
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
/////////////////////////////////////////////////////////
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):
View gissatalet.py
# Korrigerad version
# Ange ett tal
number = input("Ange ett tal mellan 1 - 100. ")
# Använd heltal
number = int(number)
# Räknare
guess = 0
View README.md