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
<!doctype html> | |
<html> | |
<!-- Reference: <https://groups.google.com/group/comp.lang.javascript/browse_thread/thread/1f5810b6d34c8d50#> --> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<div> | |
<select onchange="this.nextSibling.value = this.value;this.nextSibling.focus()" style="width:2em;margin-left:2em;vertical-align:top;height:1.5em" id="opt"> | |
<option value=""></option> |
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
datatype 'a tree = Empty | Node of {l:'a tree, x: 'a, r: 'a tree} | |
type 'a set = ('a * 'a -> bool) * 'a tree | |
(* Note to self: next time I think an AVL tree is a good idea, | |
place head in microwave until the thought goes away... *) | |
fun makeBST cmp vs = let | |
fun half ls = length ls div 2; | |
fun mergesort [] = [] | |
| mergesort [x] = [x] |
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
type vector = real list; | |
fun map2 (f1 : 'a * 'b -> 'c) (f2 : 'a -> 'c) (f3 : 'b -> 'c) (xs : 'a list) (ys : 'b list) = | |
let | |
fun m2 [] [] = [] | |
| m2 xs [] = f2 (hd xs) :: m2 (tl xs) [] | |
| m2 [] ys = f3 (hd ys) :: m2 [] (tl ys) | |
| m2 xs ys = f1 (hd xs, hd ys) :: m2 (tl xs) (tl ys) | |
in | |
m2 xs ys |
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
datatype expr = LIT of int | |
| PLUS of expr * expr | |
| TIMES of expr * expr | |
| VAR of string; | |
datatype stmt = SKIP | |
| ASSIGN of string * expr | |
| SEQ of stmt * stmt | |
| PRINT of expr | |
| IFPOS of expr * stmt * stmt |
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
# $t0 = index | |
# $t1 = character | |
# $t2 = ASCII 97 'a' | |
# $t3 = ASCII 122 'z' | |
# $t4 = string length | |
# $t5 = ASCII difference | |
# $t6 = ASCII 10 '\n' | |
# $t7 = maxlen | |
.data | |
promptString: .asciiz "\nEnter a string <= 20 characters in length (Empty string to exit): " |
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
###################################### | |
# Case insensitive Palindrome Checker | |
###################################### | |
# Register Usage | |
# $t0 = index | |
# $t1 = character | |
# $t2 = ASCII 97 'a' | |
# $t3 = ASCII 122 'z' | |
# $t4 = string length | |
# $t5 = ASCII difference |
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
//More info: <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-justice/> | |
// Imperative: O(n) time, O(1) space | |
function fib(n){ | |
if(n < 2) | |
return n; | |
var f0 = 0, f1 = 1, f; | |
for(var i = 1; i < n; i++){ |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<script type="text/javascript;version=1.8"> | |
"use strict" | |
function Range(low, high){ | |
if(!(this instanceof Range)) | |
return new Range(low,high) | |
this.low = low; |
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
function trampoline(f) { | |
while (typeof f === "function") f = f(); | |
return f; | |
} | |
function fib(n){ | |
function f(n0,n1,step){ | |
return step == n ? n1 : function() { return f(n1, n0 + n1, step +1) } | |
} | |
return trampoline(f(0,1,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
Function.prototype.valueOf = function(){ | |
id.fs.push(this) | |
} | |
function id(){ | |
var fs = [] | |
function f(x){ | |
for(var i=0,len=fs.length,v=x;i<len;v=fs[i++](v)); | |
return v | |
} |