Skip to content

Instantly share code, notes, and snippets.

Blinded by Science!

Chris Barrick cbarrick

Blinded by Science!
Block or report user

Report or block cbarrick

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
#!/usr/bin/env python3
class Position:
def __init__(self, file, offset):
'''A position has both a file and offset'''
self.file = file
self.offset = offset
def __lt__(self, other):
'''Positions are ordered first by file then by offset.'''
cbarrick / Daily Programmer - Matrix Chain
Last active Aug 27, 2018
Matrix chain multiplication test cases
View Daily Programmer - Matrix Chain


Consider the problem of matrix multiplication. A matrix A of shape (n, m) may be multiplied by a matrix B of shape (m, p) to produce a new matrix A * B of shape (n, p). The number of scalar multiplications required to perform this operation is n * m * p.

Now consider the problem of multiplying three or more matrices together. It turns out that matrix multiplication is associative, but the number of scalar multiplications required to perform such operation depends on the association.

For example, consider three matrices of the following shapes:

A: (3, 5)
B: (5, 7)
#!/usr/bin/env swipl
:- initialization(main, main).
:- use_module(library(clpfd)).
:- use_module(library(dcg/basics)).
%% tour(Shape, Tour)
% Tour is a tour of a chess board of the given Shape.
cbarrick /
Created Nov 21, 2017
mines problem
import re
import sys
import numpy as np
def read(stream=sys.stdin):
'''Read some input to get a matrix of mines.
Each row of the mine matrix is a different mine. The first column is the
current gold value. The second column is the decay rate per travel step.
cbarrick / ncdump
Last active Oct 12, 2017
ncdump and usage code
View ncdump
$ ncdump -h NAM-NMM/nam.20161111/
netcdf nam.t00z.awphys.tm00 {
reftime = 1 ;
z_HTGL3 = 2 ;
z_ISBL3 = 5 ;
z_ISBL2 = 42 ;
z_HTGL2 = 2 ;
z_HTGL1 = 2 ;
z_ISBL1 = 39 ;
View Daily Programmer #296


The puzzle is a 4x4 grid of numbers between 1 and 5. 4-connected tiles of same number form a group. For example, the following grid has five groups:

1 2 2 1
1 3 3 1
1 3 3 2
2 2 2 2
cbarrick / float_address.go
Last active May 29, 2016
An experiment to combine hashing with a floating point address space
View float_address.go
// This is an experiment to combine hashing with a floating point address space.
// # The Problem:
// In a binary search tree, we wish to assign each node a unique address such
// that nodes which sort to the right have higher addresses than nodes that sort
// to the left. We want to generate the address when the node is inserted, and
// we want addresses to be stable, meaning that new insertions will not effect
// existing addresses. We also want finite bounds on the address space.
You can’t perform that action at this time.