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
sealed trait Lambda | |
case class Var(name: String) extends Lambda { | |
override def toString: String = s"{$name}" | |
} | |
case class Abs(name: String, lambda: Lambda) extends Lambda { | |
override def toString: String = s"λ{$name}(${lambda.toString})" | |
} |
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
CFLAGS=-Wall -Wextra -pedantic -std=c11 | |
CC=clang | |
OUT=mergesort | |
$(OUT): $(OUT).c makefile | |
$(CC) $(CFLAGS) $< -o $(OUT) | |
clean: | |
$(RM) $(OUT) |
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
divides n d = n /= d && mod n d == 0 | |
eratosthenes n = | |
let | |
filter_k_rec d acc = | |
if d * d < n | |
then filter_k_rec (d + 1) $ filter (\n -> not $ divides n d) acc | |
else acc | |
in filter_k_rec 2 [1..n] |
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
module BinTree | |
( Tree, genTree | |
) where | |
import GHC.Read | |
import GHC.Show | |
import Text.ParserCombinators.ReadPrec | |
import Text.Read.Lex | |
-- defines a recursive algebraic datatype describing a binary tree |
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
abstract class LinkedList[+T] { | |
def head : T | |
def tail : Option[LinkedList[T]] | |
def map[R](f: T => R): LinkedList[R] | |
} | |
case class LinkedNode[+T](value: T, next: LinkedList[T]) extends LinkedList[T] { | |
override def head = value | |
override def tail = Option(next) | |
override def map[R](f: T => R) = LinkedNode(f(value), next.map(f)) |
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
CFLAGS=-std=c11 -g -Wall -Wextra -pedantic | |
mergesort: |
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
""" https://en.wikipedia.org/wiki/Golomb_sequence """ | |
def golomb(n): | |
d = [1] | |
for i in range(0, n - 1): | |
next_val = d[len(d) - 1] + 1 | |
d.append(next_val) | |
for j in range(0, d[next_val - 1] - 1): | |
d.append(next_val) | |
return d |
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
class MagicSquare(): | |
def __init__(self, n): | |
assert(n % 2 == 1) | |
self.n = n | |
self.matrix = list( | |
map(lambda _: | |
list(map(lambda _: 0, list(range(1, n+1)))), | |
range(1, n+1))) |
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
-module(hello). | |
-export([start/0]). | |
% entry point | |
start() -> | |
{ok, Sock} = inet_udp:open(1337), | |
io:format("opened UDP socket:~p~n", [Sock]), | |
loop(Sock). | |
% loop which holds socket ref and writes OK back to clients |
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
class Graph | |
def initialize | |
@edges = {} | |
end | |
def addEdge(src, dst) | |
@edges[src] ? (@edges[src] << dst) : (@edges[src] = [dst]) | |
@edges[dst] ? (@edges[dst] << src) : (@edges[dst] = [src]) | |
@edges.each {|k, v| v.uniq!} | |
end |
NewerOlder