Skip to content

Instantly share code, notes, and snippets.

@aasmith
Last active December 10, 2015 13:08
Show Gist options
  • Save aasmith/4438762 to your computer and use it in GitHub Desktop.
Save aasmith/4438762 to your computer and use it in GitHub Desktop.
Goofspiel!
# Generate all possible combinations for a 46-point win in the game of
# Goofspiel.
#
cards = [*1..13]
res = [*4..13].map do |n|
cards.combination(n).
select { |cards| cards.reduce(:+) == 46 }.
map(&:sort).
map(&:reverse)
end
res.flatten!(1)
res.each do |row|
str = ("%2s " * row.size)
puts str % row
end
13 12 11 10
13 12 11 9 1
13 12 11 8 2
13 12 10 9 2
13 12 11 7 3
13 12 10 8 3
13 11 10 9 3
13 12 11 6 4
13 12 10 7 4
13 12 9 8 4
13 11 10 8 4
12 11 10 9 4
13 12 10 6 5
13 12 9 7 5
13 11 10 7 5
13 11 9 8 5
12 11 10 8 5
13 12 8 7 6
13 11 9 7 6
12 11 10 7 6
13 10 9 8 6
12 11 9 8 6
12 10 9 8 7
13 12 11 7 2 1
13 12 10 8 2 1
13 11 10 9 2 1
13 12 11 6 3 1
13 12 10 7 3 1
13 12 9 8 3 1
13 11 10 8 3 1
12 11 10 9 3 1
13 12 11 5 4 1
13 12 10 6 4 1
13 12 9 7 4 1
13 11 10 7 4 1
13 11 9 8 4 1
12 11 10 8 4 1
13 12 9 6 5 1
13 11 10 6 5 1
13 12 8 7 5 1
13 11 9 7 5 1
12 11 10 7 5 1
13 10 9 8 5 1
12 11 9 8 5 1
13 11 8 7 6 1
13 10 9 7 6 1
12 11 9 7 6 1
12 10 9 8 6 1
11 10 9 8 7 1
13 12 11 5 3 2
13 12 10 6 3 2
13 12 9 7 3 2
13 11 10 7 3 2
13 11 9 8 3 2
12 11 10 8 3 2
13 12 10 5 4 2
13 12 9 6 4 2
13 11 10 6 4 2
13 12 8 7 4 2
13 11 9 7 4 2
12 11 10 7 4 2
13 10 9 8 4 2
12 11 9 8 4 2
13 12 8 6 5 2
13 11 9 6 5 2
12 11 10 6 5 2
13 11 8 7 5 2
13 10 9 7 5 2
12 11 9 7 5 2
12 10 9 8 5 2
13 10 8 7 6 2
12 11 8 7 6 2
12 10 9 7 6 2
11 10 9 8 6 2
13 12 9 5 4 3
13 11 10 5 4 3
13 12 8 6 4 3
13 11 9 6 4 3
12 11 10 6 4 3
13 11 8 7 4 3
13 10 9 7 4 3
12 11 9 7 4 3
12 10 9 8 4 3
13 12 7 6 5 3
13 11 8 6 5 3
13 10 9 6 5 3
12 11 9 6 5 3
13 10 8 7 5 3
12 11 8 7 5 3
12 10 9 7 5 3
11 10 9 8 5 3
13 9 8 7 6 3
12 10 8 7 6 3
11 10 9 7 6 3
13 11 7 6 5 4
13 10 8 6 5 4
12 11 8 6 5 4
12 10 9 6 5 4
13 9 8 7 5 4
12 10 8 7 5 4
11 10 9 7 5 4
12 9 8 7 6 4
11 10 8 7 6 4
11 9 8 7 6 5
13 12 11 4 3 2 1
13 12 10 5 3 2 1
13 12 9 6 3 2 1
13 11 10 6 3 2 1
13 12 8 7 3 2 1
13 11 9 7 3 2 1
12 11 10 7 3 2 1
13 10 9 8 3 2 1
12 11 9 8 3 2 1
13 12 9 5 4 2 1
13 11 10 5 4 2 1
13 12 8 6 4 2 1
13 11 9 6 4 2 1
12 11 10 6 4 2 1
13 11 8 7 4 2 1
13 10 9 7 4 2 1
12 11 9 7 4 2 1
12 10 9 8 4 2 1
13 12 7 6 5 2 1
13 11 8 6 5 2 1
13 10 9 6 5 2 1
12 11 9 6 5 2 1
13 10 8 7 5 2 1
12 11 8 7 5 2 1
12 10 9 7 5 2 1
11 10 9 8 5 2 1
13 9 8 7 6 2 1
12 10 8 7 6 2 1
11 10 9 7 6 2 1
13 12 8 5 4 3 1
13 11 9 5 4 3 1
12 11 10 5 4 3 1
13 12 7 6 4 3 1
13 11 8 6 4 3 1
13 10 9 6 4 3 1
12 11 9 6 4 3 1
13 10 8 7 4 3 1
12 11 8 7 4 3 1
12 10 9 7 4 3 1
11 10 9 8 4 3 1
13 11 7 6 5 3 1
13 10 8 6 5 3 1
12 11 8 6 5 3 1
12 10 9 6 5 3 1
13 9 8 7 5 3 1
12 10 8 7 5 3 1
11 10 9 7 5 3 1
12 9 8 7 6 3 1
11 10 8 7 6 3 1
13 10 7 6 5 4 1
12 11 7 6 5 4 1
13 9 8 6 5 4 1
12 10 8 6 5 4 1
11 10 9 6 5 4 1
12 9 8 7 5 4 1
11 10 8 7 5 4 1
11 9 8 7 6 4 1
10 9 8 7 6 5 1
13 12 7 5 4 3 2
13 11 8 5 4 3 2
13 10 9 5 4 3 2
12 11 9 5 4 3 2
13 11 7 6 4 3 2
13 10 8 6 4 3 2
12 11 8 6 4 3 2
12 10 9 6 4 3 2
13 9 8 7 4 3 2
12 10 8 7 4 3 2
11 10 9 7 4 3 2
13 10 7 6 5 3 2
12 11 7 6 5 3 2
13 9 8 6 5 3 2
12 10 8 6 5 3 2
11 10 9 6 5 3 2
12 9 8 7 5 3 2
11 10 8 7 5 3 2
11 9 8 7 6 3 2
13 9 7 6 5 4 2
12 10 7 6 5 4 2
12 9 8 6 5 4 2
11 10 8 6 5 4 2
11 9 8 7 5 4 2
10 9 8 7 6 4 2
13 8 7 6 5 4 3
12 9 7 6 5 4 3
11 10 7 6 5 4 3
11 9 8 6 5 4 3
10 9 8 7 5 4 3
13 12 6 5 4 3 2 1
13 11 7 5 4 3 2 1
13 10 8 5 4 3 2 1
12 11 8 5 4 3 2 1
12 10 9 5 4 3 2 1
13 10 7 6 4 3 2 1
12 11 7 6 4 3 2 1
13 9 8 6 4 3 2 1
12 10 8 6 4 3 2 1
11 10 9 6 4 3 2 1
12 9 8 7 4 3 2 1
11 10 8 7 4 3 2 1
13 9 7 6 5 3 2 1
12 10 7 6 5 3 2 1
12 9 8 6 5 3 2 1
11 10 8 6 5 3 2 1
11 9 8 7 5 3 2 1
10 9 8 7 6 3 2 1
13 8 7 6 5 4 2 1
12 9 7 6 5 4 2 1
11 10 7 6 5 4 2 1
11 9 8 6 5 4 2 1
10 9 8 7 5 4 2 1
12 8 7 6 5 4 3 1
11 9 7 6 5 4 3 1
10 9 8 6 5 4 3 1
11 8 7 6 5 4 3 2
10 9 7 6 5 4 3 2
10 8 7 6 5 4 3 2 1
Find combos that do not use the king, queen, two or ace (note spaces):
egrep -v "13|12| 2 | 1 " combos-46.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment