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
public class Main { | |
// runs in O(n) time | |
// exercise: Why might this algorithm run slower than we'd like for large n? | |
// Write an iterative solution that does not suffer from | |
// the same problem. | |
public static void computeTicksIterative(int[] ruler, int n) { | |
for (int tickHeight = 1; tickHeight <= n; tickHeight++) { | |
int rulerLength = 1<<tickHeight; | |
for (int i = (rulerLength)/2; i < ruler.length; i += rulerLength) { |
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
(define-syntax or | |
(syntax-rules () | |
((_) #f) | |
((_ a rest ...) (let ((tmp a)) (if tmp tmp (or rest ...)))))) |
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
(define-syntax or | |
(syntax-rules () | |
((_) #f) | |
((_ a rest ...) (let ((tmp a)) (if tmp tmp (_ rest ...)))))) |
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
#include <iostream> | |
#include <string> | |
using namespace std; | |
/* START AUTO POINTER IMPLEMENTATION */ | |
class super_wrapped_object { | |
public: | |
virtual void refCountDown() = 0; | |
virtual void refCountUp() = 0; |
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
#lang racket | |
; box functions | |
(define (box x) | |
(lambda (m) | |
(m x (lambda (new) (set! x new))))) | |
(define (unbox b) | |
(b (lambda (x set) 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
points = [(447, 13), (460, 21), | |
(481, 24), (498, 16), | |
(513, 24), (512, 20), | |
(526, 15), (559, 34), | |
(585, 33), (614, 33), | |
(645, 39), (675, 43), | |
(711, 50), (719, 47)] | |
def mean(i): | |
s = 0 |
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 itertools import * | |
from random import * | |
from collections import defaultdict | |
shuffled = range(1, 101) | |
shuffle(shuffled) | |
shuffled = shuffled[:10] | |
sums = defaultdict(list) | |
print "random list of numbers from 1 to 100:\n" + str(shuffled) |
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
#include <iostream> | |
#include <vector> | |
std::vector<bool> v; | |
decltype(v[0]) first() { | |
return v[0]; | |
} | |
int main() { |
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
#include <iostream> | |
#include <vector> | |
std::vector<bool> v; | |
int main() { | |
v.push_back(true); | |
auto r = v[0]; |
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
#include <iostream> | |
#include <vector> | |
std::vector<bool> v; | |
bool& first() { | |
return v[0]; | |
} | |
int main() { |