Last active
June 10, 2020 19:22
-
-
Save pgblu/35f43ea1ada7a20a785cf5e0056418eb to your computer and use it in GitHub Desktop.
All possibilities for fulfilling any Parity Party clue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digits = (1..9).to_a | |
evens, odds = [0,1].map {|num| digits.select{ |k| k % 2 == num}} | |
def all_subsets(ar) | |
result = [] | |
0.upto(ar.length) do |num| | |
result += ar.combination(num).to_a | |
end | |
result | |
end | |
def zipped_groups(num, ar) | |
ar.map{|s| [s, num]} | |
end | |
def collection(ar1, ar2) | |
ar1.map{|num| zipped_groups(num, all_subsets(ar2))} | |
end | |
def render_possibility_word(num) | |
"(#{num} possibilit#{num == 1 ? "y" : "ies"})" | |
end | |
(collection(odds, evens).flatten(1) + collection(evens, odds).flatten(1)).group_by do |coll| | |
coll.flatten.reduce(:+) | |
end.sort_by {|h,k| h}.map do |group| | |
puts "#{group[0]} #{render_possibility_word(group[1].length)}: #{group[1].sort_by{|blob| grp = blob[0]; [grp.length, grp.empty? ? 0 : grp.reduce(:+)]}}" | |
end | |
=begin | |
<---begin output---> | |
1 (1 possibility): [[[], 1]] | |
2 (1 possibility): [[[], 2]] | |
3 (3 possibilities): [[[], 3], [[1], 2], [[2], 1]] | |
4 (1 possibility): [[[], 4]] | |
5 (5 possibilities): [[[], 5], [[1], 4], [[2], 3], [[3], 2], [[4], 1]] | |
6 (2 possibilities): [[[], 6], [[1, 3], 2]] | |
7 (8 possibilities): [[[], 7], [[1], 6], [[2], 5], [[3], 4], [[4], 3], [[5], 2], [[6], 1], [[2, 4], 1]] | |
8 (3 possibilities): [[[], 8], [[1, 3], 4], [[1, 5], 2]] | |
9 (11 possibilities): [[[], 9], [[1], 8], [[2], 7], [[3], 6], [[4], 5], [[5], 4], [[6], 3], [[7], 2], [[8], 1], [[2, 4], 3], [[2, 6], 1]] | |
10 (4 possibilities): [[[1, 3], 6], [[1, 5], 4], [[1, 7], 2], [[3, 5], 2]] | |
11 (13 possibilities): [[[2], 9], [[3], 8], [[4], 7], [[5], 6], [[6], 5], [[7], 4], [[8], 3], [[9], 2], [[2, 4], 5], [[2, 6], 3], [[2, 8], 1], [[4, 6], 1], [[1, 3, 5], 2]] | |
12 (6 possibilities): [[[1, 3], 8], [[1, 5], 6], [[1, 7], 4], [[3, 5], 4], [[1, 9], 2], [[3, 7], 2]] | |
13 (14 possibilities): [[[4], 9], [[5], 8], [[6], 7], [[7], 6], [[8], 5], [[9], 4], [[2, 4], 7], [[2, 6], 5], [[4, 6], 3], [[2, 8], 3], [[4, 8], 1], [[1, 3, 5], 4], [[1, 3, 7], 2], [[2, 4, 6], 1]] | |
14 (7 possibilities): [[[1, 5], 8], [[1, 7], 6], [[3, 5], 6], [[1, 9], 4], [[3, 7], 4], [[3, 9], 2], [[5, 7], 2]] | |
15 (16 possibilities): [[[6], 9], [[7], 8], [[8], 7], [[9], 6], [[2, 4], 9], [[2, 6], 7], [[2, 8], 5], [[4, 6], 5], [[4, 8], 3], [[6, 8], 1], [[1, 3, 5], 6], [[1, 3, 7], 4], [[2, 4, 6], 3], [[1, 3, 9], 2], [[1, 5, 7], 2], [[2, 4, 8], 1]] | |
16 (7 possibilities): [[[1, 7], 8], [[3, 5], 8], [[1, 9], 6], [[3, 7], 6], [[3, 9], 4], [[5, 7], 4], [[5, 9], 2]] | |
17 (16 possibilities): [[[8], 9], [[9], 8], [[2, 6], 9], [[2, 8], 7], [[4, 6], 7], [[4, 8], 5], [[6, 8], 3], [[1, 3, 5], 8], [[1, 3, 7], 6], [[2, 4, 6], 5], [[1, 5, 7], 4], [[1, 3, 9], 4], [[2, 4, 8], 3], [[3, 5, 7], 2], [[1, 5, 9], 2], [[2, 6, 8], 1]] | |
18 (7 possibilities): [[[1, 9], 8], [[3, 7], 8], [[3, 9], 6], [[5, 7], 6], [[5, 9], 4], [[7, 9], 2], [[1, 3, 5, 7], 2]] | |
19 (15 possibilities): [[[4, 6], 9], [[2, 8], 9], [[4, 8], 7], [[6, 8], 5], [[1, 3, 7], 8], [[2, 4, 6], 7], [[1, 5, 7], 6], [[1, 3, 9], 6], [[2, 4, 8], 5], [[1, 5, 9], 4], [[3, 5, 7], 4], [[2, 6, 8], 3], [[1, 7, 9], 2], [[3, 5, 9], 2], [[4, 6, 8], 1]] | |
20 (6 possibilities): [[[3, 9], 8], [[5, 7], 8], [[5, 9], 6], [[7, 9], 4], [[1, 3, 5, 7], 4], [[1, 3, 5, 9], 2]] | |
21 (14 possibilities): [[[4, 8], 9], [[6, 8], 7], [[2, 4, 6], 9], [[1, 3, 9], 8], [[1, 5, 7], 8], [[2, 4, 8], 7], [[3, 5, 7], 6], [[1, 5, 9], 6], [[2, 6, 8], 5], [[1, 7, 9], 4], [[3, 5, 9], 4], [[4, 6, 8], 3], [[3, 7, 9], 2], [[2, 4, 6, 8], 1]] | |
22 (5 possibilities): [[[5, 9], 8], [[7, 9], 6], [[1, 3, 5, 7], 6], [[1, 3, 5, 9], 4], [[1, 3, 7, 9], 2]] | |
23 (11 possibilities): [[[6, 8], 9], [[2, 4, 8], 9], [[1, 5, 9], 8], [[3, 5, 7], 8], [[2, 6, 8], 7], [[3, 5, 9], 6], [[1, 7, 9], 6], [[4, 6, 8], 5], [[3, 7, 9], 4], [[5, 7, 9], 2], [[2, 4, 6, 8], 3]] | |
24 (5 possibilities): [[[7, 9], 8], [[1, 3, 5, 7], 8], [[1, 3, 5, 9], 6], [[1, 3, 7, 9], 4], [[1, 5, 7, 9], 2]] | |
25 (7 possibilities): [[[2, 6, 8], 9], [[1, 7, 9], 8], [[3, 5, 9], 8], [[4, 6, 8], 7], [[3, 7, 9], 6], [[5, 7, 9], 4], [[2, 4, 6, 8], 5]] | |
26 (4 possibilities): [[[1, 3, 5, 9], 8], [[1, 3, 7, 9], 6], [[1, 5, 7, 9], 4], [[3, 5, 7, 9], 2]] | |
27 (5 possibilities): [[[4, 6, 8], 9], [[3, 7, 9], 8], [[5, 7, 9], 6], [[2, 4, 6, 8], 7], [[1, 3, 5, 7, 9], 2]] | |
28 (3 possibilities): [[[1, 3, 7, 9], 8], [[1, 5, 7, 9], 6], [[3, 5, 7, 9], 4]] | |
29 (3 possibilities): [[[5, 7, 9], 8], [[2, 4, 6, 8], 9], [[1, 3, 5, 7, 9], 4]] | |
30 (2 possibilities): [[[1, 5, 7, 9], 8], [[3, 5, 7, 9], 6]] | |
31 (1 possibility): [[[1, 3, 5, 7, 9], 6]] | |
32 (1 possibility): [[[3, 5, 7, 9], 8]] | |
33 (1 possibility): [[[1, 3, 5, 7, 9], 8]] | |
<---end output---> | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment