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
# linalg.py - vector and matrix handling | |
# | |
# Copyright 2011 Jonathan D. Page. All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without modification, are | |
# permitted provided that the following conditions are met: | |
# | |
# 1. Redistributions of source code must retain the above copyright notice, this list of | |
# conditions and the following disclaimer. | |
# |
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
#!/usr/bin/env python | |
import sys | |
from collections import deque | |
SINGLE, SHIFT_LEFT_SEQ, SHIFT_RIGHT_SEQ, INC_SEQ, DEC_SEQ = range(5) | |
SHIFT_RIGHT = ord('>') # increment the data pointer | |
SHIFT_LEFT = ord('<') # decrement the data pointer | |
INC = ord('+') # increment the current byte |
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 __future__ import division | |
from visual import * | |
from math import * | |
PROTON_CHARGE = 100 | |
MU_ZERO = 1.256e-6 | |
VEL = vector(.01, 0, 0) # m/s | |
SCALE = 20 | |
observation_points = [vector(x * .01 - .1, .01 * cos(pi/4 * t), .01 * sin(pi/4 * t)) for x in range(20) for t in range(8)] |
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 __future__ import division | |
from math import pi | |
def grader(target): | |
return lambda (p1, q1), (p2, q2): cmp(abs(target - p1 / q1), abs(target - p2 / q2)) | |
def gcd(a, b): | |
# euclid's algorithm | |
while a != b: | |
if b < a: |
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 java.lang.reflect.Method; | |
import java.lang.reflect.Field; | |
public class FooTest { | |
static class Foo { | |
private int hehe = 0; | |
private void doSomething() { | |
System.out.println("Foo!"); | |
} |
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 java.lang.reflect.Method; | |
import java.lang.reflect.Field; | |
public class FooTest { | |
static class Foo { | |
private int hehe = 0; | |
private void doSomething() { | |
System.out.println("Foo!"); | |
} |
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
open System | |
let rec sorted = function | |
| (x :: xs) -> | |
let left, right = List.partition (fun i -> i < x) xs | |
let sleft = sorted left | |
let sright = sorted right | |
sleft @ (x :: sright) | |
| [] -> [] |
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
#!/usr/bin/python3 | |
import random | |
def sorted(l): | |
if len(l) == 0: | |
return l | |
else: | |
x, *xs = l | |
left, right = [], [] |
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
class Add extends Func2<Integer, Integer, Integer> { | |
@Override | |
public Integer apply(Integer a, Integer b) { | |
return a + b; | |
} | |
} |
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 __future__ import division | |
from fractions import gcd | |
from itertools import izip, tee, izip_longest | |
import sys | |
def pi_noncanon_seq(): | |
""" | |
produces a generalized continued fraction from of pi, starting with | |
(0 4) (1 1) (3 4) (5 9) ... | |
""" |
OlderNewer