Instantly share code, notes, and snippets.

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
View concurrency-exercise.go
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
View 6174.go
// https://en.wikipedia.org/wiki/6174_(number)
package main
import (
"fmt"
"sort"
"strconv"
)
View hashlist.c
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define SIZE 256
struct element {
char *key;
double value;