This file contains 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
/ script to expose an apparent bug in kona when combining | |
/ higher-order verbs. | |
/ j-style "monadic fork": our first higher order verb. | |
mf: {[f;g;h] { g[f[x]; h[x]] }} | |
/ cheq = check equality of two strings. (or complain if mismatched) | |
cheq: { :[ x~y; echo "."; echo "\nfailed: (", x, ") ~ (", y, ")\n"] } | |
This file contains 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
DROP TABLE IF EXISTS x; | |
CREATE TABLE x ( | |
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
x_data CHAR(6) NOT NULL, | |
x_hash CHAR(6) UNIQUE NOT NULL); | |
-- Change the delimiter so we can use ';' in the trigger. | |
DELIMITER $$ |
This file contains 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
theory QSort | |
imports Main | |
begin | |
fun qsort :: "'a::ord list ⇒ 'a list" where | |
"qsort [] = []" | |
| "qsort (x#xs) = (qsort (filter (λy. y≤x) xs)) | |
@ x#(qsort (filter (λy. y>x) xs))" | |
This file contains 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
theory SumOfRange | |
imports Main | |
begin | |
fun sum :: "nat list ⇒ nat" where | |
"sum xs = foldl (op+) 0 xs" | |
fun egnar :: "nat ⇒ nat list" where | |
"egnar x = (if x ≤ 0 then [] else x # egnar (x-1))" |
This file contains 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
: make-array ( n -- ) cells allot ; | |
: fill-array ( count addr val -- ) | |
( figure this out yourself ) | |
; | |
: zeros ( n -- ) dup here swap make-array 0 fill-array ; | |
( usage example: ) |
This file contains 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
defmodule QuickSort do | |
@doc "return a random 32-bit integer" | |
def rand(), do: round(:rand.uniform(round(:math.pow(2,31))) - :math.pow(2,30)) | |
@doc "return a list of n random 32-bit integers" | |
def rand_nums_works(n) do for _ <- 1..n do rand end end | |
@doc "return a list of n random 32-bit integers" | |
def rand_nums_fails(n), do: for _ <- 1..n do rand end |
This file contains 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
import os | |
def parse(filename): | |
data = {} | |
for line in open(filename).read().split("\n"): | |
if not line.strip(): continue | |
for pair in line.split(';'): | |
key, val = pair.split('.') | |
data[key]=val | |
return data |
This file contains 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
defmodule Elixtris do | |
def main(buf) do | |
if buf == '' do main(IO.gets('') |> String.to_char_list) | |
else [ch|tail] = buf | |
unless [ch] == 'q' do | |
case [ch] do | |
'p' -> IO.puts("not yet") | |
' ' -> [] | |
'\n' -> [] | |
ch -> IO.puts('unknown command:' ++ [ch]) |
This file contains 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
goal: 66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925 | |
mine: 66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925 |
This file contains 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
from operator import add,mul | |
class nda(list): | |
"""n-dimensional arrays""" | |
rot=lambda xs,n: nda(xs[-n:] + xs[:-n][:n] + xs[n:-n]) # rotate | |
len=lambda xs : nda([len(xs)]) # length | |
wrp=lambda xs,n: nda([nda(xs[i:i+n]) for i in range(0,len(xs),n)]) # wrap | |
rsh=lambda xs,n,*ns: nda(sum([w.rsh(*ns) for w in xs.wrp(n)],[]) if ns else xs.wrp(n)) # reshape | |
prod=lambda xs: reduce(mul, xs) # product |