Skip to content

Instantly share code, notes, and snippets.

@jsomers
jsomers / puzzles.rb
Created February 4, 2011 15:02
A script that finds unique word templates
words = File.open("./TWL06.txt").read.downcase.gsub("\r", "").split("\n")
words.select! {|w| w.length == 6}
# Approach:
# 1. Generate an index that maps 2-templates (like "_l___x") to words ("climax").
# 2. Find 2-templates that map to just one word.
def templates(word)
"Finds all fifteen (6! / 4! * 2!) 2-templates for a given word."
inds = []; (0..4).collect {|i| (i + 1..5).each {|j| inds << [i, j]}}
@jsomers
jsomers / mindy.rb
Created April 25, 2010 07:58
Functions for dealing and scoring games of Mindy Coat
# The Rules of Mindy Coat
# =======================
# => Four players, opposite sides are in teams.
# => Deal 5 cards each, one-by-one starting left of the dealer.
# => Left of the dealer calls trump looking at those 5.
# => Dealer deals the last 8 cards out (starts on the left).
# => Highest card of the trick wins, unless a trump is thrown, in which case the highest trump wins.
# => Team that takes the most tens wins, unless each takes two, in which case the total number of tricks is counted.
# => (Must follow suit unless you don't have it.)
@jsomers
jsomers / ghost.rb
Created April 24, 2010 23:35
Code to help analyze games of Ghost
Words = File.new("./pruned-words.txt").read.split("\n")
class String
def starts_with?(str)
self[0..str.length - 1] == str
end
end
# Players can never play "bones", e.g., since the game would end with "bone".
# The next two functions remove all 128,832 such extraneous words from our word list.