Last active
September 25, 2015 08:18
-
-
Save jsomers/891860 to your computer and use it in GitHub Desktop.
complex sporcle-like word puzzles
This file contains hidden or 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
N = 6 | |
R = 2 | |
def masks | |
@masks ||= (0..N - 1).to_a.combination(N - R).to_a | |
end | |
def templates(word) | |
masks.inject([]) do |templates, indexes_to_hide| | |
arr = word.split('') | |
indexes_to_hide.each { |i| arr[i] = "_" } | |
templates << arr.join("") | |
end | |
end | |
words = File.open('./TWL06.txt').readlines.map(&:chomp).select { |w| w.length == N } | |
index = words.inject(Hash.new(0)) do |idx, word| | |
templates(word).each { |t| idx[t] += 1 } | |
idx | |
end | |
puts index.select { |_, v| v == 1 }.map(&:first) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare the method of generating all of the (6c2 * 262 = 10,140) templates first. There, for every template you'd have to check all of the words. Here you're only doing 15 ops per word.