Skip to content

Instantly share code, notes, and snippets.

View cbarrick's full-sized avatar
💭
Daydreaming in the Herbrand Universe

Chris Barrick cbarrick

💭
Daydreaming in the Herbrand Universe
View GitHub Profile
@cbarrick
cbarrick / float_address.go
Last active May 29, 2016 21:43
An experiment to combine hashing with a floating point address space
// 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.
//

Description

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
cbarrick / ncdump
Last active October 12, 2017 20:27
ncdump and usage code
$ ncdump -h NAM-NMM/nam.20161111/nam.t00z.awphys.tm00.nc
netcdf nam.t00z.awphys.tm00 {
dimensions:
reftime = 1 ;
z_HTGL3 = 2 ;
z_ISBL3 = 5 ;
z_ISBL2 = 42 ;
z_HTGL2 = 2 ;
z_HTGL1 = 2 ;
z_ISBL1 = 39 ;
@cbarrick
cbarrick / mines.py
Created November 21, 2017 00:44
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.
#!/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
cbarrick / Daily Programmer - Matrix Chain Multiplication.md
Last active December 12, 2021 16:07
Matrix chain multiplication test cases

Description

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 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
cbarrick / [0] TicTacToe-base3.md
Last active May 14, 2024 16:28
Encoding tic-tac-toe in 15 bits

Test cases for the blog post [Encoding tic-tac-toe in 15 bits][post].

Run like this:

# Base4 test
$ cc base4.c && ./a.out

# Base3 test
$ cc base3.c && ./a.out