Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE FlexibleInstances #-}
-- From exercise 2.40 in Algebra of Programming (Bird, 1997)
data TreeF a b = Leaf a | Branch b b
newtype Mu f = InF { outF :: f (Mu f) }
type Tree a = Mu (TreeF a)
Program Quicksort;
{
My first Pascal code.
Populates and array numbers of length N with random numbers between 1 and M, sorts it in place using quicksort, then prints each element of the list.
The quicksort algorithm is translate from C as found in "The Most Beautiful Code I Never Wrote" by Jon Bentley as found in the book "Beautiful Code"
}
Uses math;
Const
#!/usr/bin/env python3
from sys import stdin
from sys import argv
from collections import defaultdict
# Adapted from Intro to Algorithms by CLRS.
# A string matching automata similar to grep.
def computeTransitionFunction(pattern):
m = len(pattern)
@newjam
newjam / pq.py
Created February 20, 2019 07:09
from heapq import heappush, heappop
schedule = [(1, 3), (2, 5), (4, 5)]
def required_rooms(schedule):
h = []
for start, end in schedule:
if len(h) > 0 and h[0] <= start:
heappop(h)
heappush(h, end)
; https://leetcode.com/problems/3sum-closest/
(declare-const a Int)
(declare-const b Int)
(declare-const c Int)
(assert (or (= a -1) (= a 2) (= a 1) (= a -4)))
(assert (or (= b -1) (= b 2) (= b 1) (= b -4)))
(assert (or (= c -1) (= c 2) (= c 1) (= c -4)))
hello
@newjam
newjam / foo.rb
Created September 14, 2018 11:09
#!/usr/bin/env ruby
require 'net/ssh'
def main
if ARGV.size < 3 then
puts 'usage: <hostname> <username> <password>'
else
hostname = ARGV[0]
username = ARGV[1]
{-# LANGUAGE ExistentialQuantification #-}
-- DFA borrowed from Romain Ruetschi on github: https://gist.github.com/romac/9193493
module DFA (
DFA(..),
runDFA,
scanDFA,
isAccepting,
) where
module test;
reg clk;
wire out;
initial begin
$display("newjam wave decoder");
clk = 0;
//$monitor("%s", out);
end