Skip to content

Instantly share code, notes, and snippets.

View kbob's full-sized avatar

Bob Miller kbob

  • Eugene, Oregon, USA
View GitHub Profile
// C++
// ref. https://gist.github.com/817504
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
class counter {
@kbob
kbob / gist:820127
Created February 10, 2011 08:17
A Mildly Amusing (I hope) Anecdote Involving Ken Olsen, RIP

A Mildly Amusing (I hope) Anecdote Involving Ken Olsen, RIP by Barry Shein on Wednesday, February 9, 2011 at 4:07pm

In the early 1980s I was in charge of the Harvard chemistry computing facility for about a year. We had a Vax 11/780 and a fancy Evans & Sutherland graphics tube (it had its own embedded PDP11/70!), amazing device, and other stuff.

Our 780 had the extra double-wide memory cabinet -- a whopping 8MB total which at the time was a lot. This cabinet was the size of two full-sized refrigerators side by side, just for the extra memory.

The 4MB in that second cabinet wasn't ours. We let a very small company which made 3rd party memory boards for the Vax exercise their new boards in our machine. We got an extra 4MB, they got their memory tested. This arrangement preceded my arrival but it seemed win/win. We got to use what was a lot of memory for the time, probably $50,000 worth of memory, they got their boards tested.

The arrangement meant that every couple of weeks I'd have to meet the guy who basi

@kbob
kbob / gist:898702
Created April 1, 2011 19:27
Test whether program compiled with tail call optimization.
#include <stdio.h>
/*
* In a separate compilation unit, save is defined as:
*
* void save(int *p)
* {
* *p = (int)&p;
* }
*/
@kbob
kbob / fizzbuzz.py
Created November 22, 2012 23:36
FizzBuzz
#!/usr/bin/python
from itertools import count, cycle, islice, izip, repeat
def fizzbuzz(n):
class d(int): __add__ = lambda self, other: other
def i(x): return x
def f(x): return x + 'Fizz'
def b(x): return x + 'Buzz'
def p(x): print x
@kbob
kbob / nonrepeating_digits.py
Last active December 10, 2015 01:18
https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ There are no repeated digits, and no adjacent digits with a difference of one, in the number 13524. How many such arrangements of 5 digits are there? What's the shortest program you can write to find out?
#!/usr/bin/python
# https://plus.google.com/u/0/114070220225686847236/posts/d7xrq9ph7WJ
# There are no repeated digits, and no adjacent digits with a
# difference of one, in the number 13524. How many such arrangements
# of 5 digits are there? What's the shortest program you can write to
# find out?
import itertools
@kbob
kbob / Ramanujan_number.py
Created December 23, 2012 16:43
Find Ramanujan's number.
#!/usr/bin/python
from itertools import count
def ramanujan_number():
cubes = (i**3 for i in count(1))
smaller_cubes = []
sums = {}
for n in cubes:
for m in smaller_cubes:
@kbob
kbob / infinite_combinations.py
Created December 23, 2012 18:16
Iterate combinations of an infinite set
import itertools
def infinite_combinations(n, iterator):
seen = []
for item in iterator:
for subset in itertools.combinations(seen, n - 1):
yield subset + (item,)
seen.append(item)
// Polyphase decimation filter.
//
// Convert an oversampled audio stream to non-oversampled. Uses a
// windowed sinc FIR filter w/ Blackman window to control aliasing.
// Christian Floisand's 'blog explains it very well.
//
// This version has a very simple main processing loop (the decimate
// method) which vectorizes easily.
//
// Refs:
@kbob
kbob / main.rs
Created February 20, 2016 21:53
Trie insertion and query
struct TrieNode {
is_terminal: bool,
children: [Option<Box<TrieNode>>; 256],
}
impl TrieNode {
fn new() -> TrieNode {
let mem : TrieNode = unsafe { std::mem::zeroed() };
mem
}
@kbob
kbob / print_nine_digit_positive.c
Created June 10, 2016 20:22
Silly unrolled print function
#include <assert.h>
#include <stdint.h>
#include <unistd.h>
/* print nine digit positive */
char *p9dp(uint32_t n, char *p)
{
uint32_t a = n % 10;
n /= 10;
if (n) {