Skip to content

Instantly share code, notes, and snippets.

@kierendavies
kierendavies / cube-puzzle-solver.rb
Last active August 29, 2015 14:19
Solver for the coloured-cubes puzzle that Caleb brought
# This program solves a puzzle I encountered recently.
# The puzzle consists of four cubes, each face of which has one of four colours.
# The objective is to arrange them in a column so that, looking down each side
# of the column, the four visible colours are all different.
require 'pp'
require 'set'
# A cube with colours attributed to its faces.
class Cube
; Burrows-Wheeler Transform (and inverse)
; http://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
(def string-start \u0098)
(defn bwt [s]
(map last
(sort-by vec
(take (inc (count s))
(iterate #(concat (rest %)