Skip to content

Instantly share code, notes, and snippets.

View tuzz's full-sized avatar

Chris Patuzzo tuzz

View GitHub Profile
@tuzz
tuzz / domain_packing.snt
Created July 28, 2017 11:36
Domain Packing
# I have a problem at work that I _think_ is the Knapsack Problem but perhaps
# someone here can help me research/find a heuristic solution: we have access
# to the <redacted> and get a finite number of “rules” we can use (e.g. 1000)
# and each rule can only be 1024 characters long and have a maximum of 30
# operators in them (e.g. “foo OR bar OR baz”), we have a list of domains
# (e.g. example.com, example.org) we want to pack domains into rules as
# efficiently as possible in the minimum number of rules.
# Here's an attempt at a Sentient program to solve the decision version of
# this problem, i.e. Can 100 domains fit into 5 rules?
# A Sentient program in response to this tweet:
# https://twitter.com/jamestanton/status/874962919963885568
#
# Run it with:
# for i in {1..100}; do ruby search.rb $i > search.snt && sentient -c -o -r -n 0 -m lingeling search.snt; done
n = Integer(ARGV.first)
program = <<-SNT
array#{n}<int5> numbers;
@tuzz
tuzz / buckets.snt
Last active April 6, 2017 22:01
Solves the three and five gallon bucket problem with Sentient.
# A Sentient[1] program that solves this problem:
#
# Given three and five gallon buckets and a water supply, fill the five gallon
# bucket with four gallons of water. [2]
#
# [1] http://sentient-lang.org/
# [2] http://nchammas.com/writing/how-not-to-die-hard-with-hypothesis
#
# Sentient solves this in a minimum of six steps:
#
@tuzz
tuzz / README.md
Last active February 24, 2017 00:37
A jumble of thoughts

I've been thinking about pre-computing a database of pangram solutions. Why?

  • I think it would be fun
  • I like the idea of showing solutions in real-time as you type
  • I'm interested in patterns/stats relating to the set

I started thinking about which pangrams I should pre-compute, e.g.

  • "This seventy first pangram contains ..."
  • "This pangram is dedicated to John Smith and it contains ..."
@tuzz
tuzz / extract.rb
Created January 10, 2017 22:36
Extract boolean equation from a compiled sentient program
dimacs = JSON.parse(File.read("foo.json"))["dimacs"].split("\n")[1..-1].map { |line| line.split(" ")[0..-2].map { |s| s.start_with?("-") ? "!x#{s[1..-1]}" : "x#{s}" }.join(" || ") }.map { |line| "(#{line})" }.join(" && ")
@tuzz
tuzz / rudolph.snt
Last active December 21, 2016 09:32
Reindeer emergency!!!
# Five of Santa's reindeer are lost.
#
# Rudolph has found them by the frozen waterfall, and knows the way back to
# Santa's stable.
#
# But Rudolph's nose will only light the way for one or two other reindeer at a
# time, so he cannot travel with more.
#
# And unfortunately, Rudolph doesn't know the quickest route from the stable to
# the waterfall (and he won't learn it either), so he can't make the journey
@tuzz
tuzz / sudoku.snt
Created November 10, 2016 00:10
My canonical solution for solving a Sudoku in Sentient
function main () {
array9<array9<int5>> sudoku;
sudoku.each(function (row) {
invariant row.uniq?;
invariant row.all?(function (n) {
return n.between?(1, 9);
});
});
@tuzz
tuzz / N=200
Last active August 14, 2016 00:11
N=200
For which N is there a permutation of {1,...,N} s.t. termwise sum with {1,...,N} gives all squares?
Here's a solution for N=200, solved with http://sentient-lang.org/
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
@tuzz
tuzz / combinations_spec.rb
Created July 22, 2016 14:32
Generates combinations from an array
require "rspec"
def combinations(array, length)
if length.zero?
[[]]
else
array.flat_map.with_index do |element, index|
tail = array[(index + 1)..-1]
combinations(tail, length - 1).map do |combination|
@tuzz
tuzz / riss-427-mac-os-x.patch
Created May 30, 2016 11:09
Port Riss 4.27 and Coprocessor to Mac OS X
From efc06ffab5435b4686f3889167a7d5260de4e1fe Mon Sep 17 00:00:00 2001
From: Chris Patuzzo <chris@patuzzo.co.uk>
Date: Mon, 30 May 2016 11:59:11 +0100
Subject: [PATCH 1/1] Port Riss 4.27 and Coprocessor to Mac OS X
---
Makefile | 5 ++---
coprocessor-src/BoundedVariableEliminationParallel.cc | 2 +-
coprocessor-src/Coprocessor.cc | 9 +--------
coprocessor-src/Coprocessor.h | 12 +++++-------