The Art of Computer Programming (Knuth)
Programming Pearls (Bentley)
Data Structures and Algorithms (Aho, Hopcroft, Ullman)
#!/usr/bin/env python3 | |
def population(bits, start=0): | |
return sum(bits[i] for i in range(start, len(bits))) | |
def product(iterable): | |
import functools, operator | |
return functools.reduce(operator.mul, iterable, 1) | |
def n_choose_k(n, k): |
// Run this with scala <filename> | |
import java.util.concurrent.atomic.AtomicLong | |
val txIds = new AtomicLong(0) | |
// Dummied up transaction id provider | |
def nextTxId = txIds.incrementAndGet | |
/** |
T | |
F | |
v1 | |
w1 | |
(and v1 v2) | |
(and w1 w2) | |
(and v1 w2) | |
(or v1 v2) | |
(or w1 w2) | |
(or v1 w2) |
import scala.annotation.tailrec | |
import scala.util.Random | |
/* | |
* Pick a random number between to double values, inclusive. | |
*/ | |
@tailrec def between(low: Double, high: Double, r: Random): Double = { | |
if (low == high) { | |
low | |
} else { |
I hereby claim:
To claim this, I am signing this object:
. 5 . | . . 1 | 4 7 9 | |
. . 2 | 7 . . | . . 8 | |
. . . | . 4 6 | 2 . . | |
------+-------+------ | |
. 4 6 | . . 9 | 5 3 7 | |
. . . | . 6 . | . . . | |
8 9 3 | 5 . . | 6 4 . | |
------+-------+------ | |
. . 9 | 6 1 . | . . . | |
1 . . | . . 2 | 3 . . |
#!/usr/bin/env python3 | |
# Reader -- parses text to something, some structure. | |
# Python lists for lists. | |
# Instances of Symbol for symbols. | |
# Numbers for numbers. | |
# Strings for strings. | |
# ??? for functions |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.TimeZone; | |
import java.util.GregorianCalendar; | |
public class Foo { | |
public static void main(String[] argv) { | |
TimeZone utc = TimeZone.getTimeZone("UTC"); |
import Data.Array | |
import Data.Maybe | |
import Data.List.Split | |
import System.Environment | |
import System.IO | |
direction "n" = \(r, c) -> (r - 1, c) | |
direction "s" = \(r, c) -> (r + 1, c) | |
direction "e" = \(r, c) -> (r, c + 1) | |
direction "w" = \(r, c) -> (r, c - 1) |