blob: 310f82364c5eecd6e291a8472aa174ccbd94397c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
require 'sqlite3'
db = SQLite3::Database.open ARGV[0]
form_rows = db.query "SELECT form FROM forms WHERE proper = 0"
wanderlust = {}
wanderlust["w"] = "1"
wanderlust["a"] = "2"
wanderlust["n"] = "3"
wanderlust["d"] = "4"
wanderlust["e"] = "5"
wanderlust["r"] = "6"
wanderlust["l"] = "7"
wanderlust["u"] = "8"
wanderlust["s"] = "9"
wanderlust["t"] = "0"
forms = form_rows.map {|row| row[0].downcase}
orange_forms = forms.reject {|form| /^[wanderlust]*$/.match(form).nil?}.select {|form| form.length >= 3}
words = orange_forms.map do |form|
oranged = form.chars.map {|letter| wanderlust[letter]}.join
[form, oranged, oranged.to_i]
end
words.sort_by! {|word| word[2]}
puts words.length
puts words[10]
puts words.sample
puts ""
oranges_by_num = {}
puzzles = []
words.each do |vals|
oranges_by_num.each do |num, form|
opposite = (vals[2] - num.to_i).to_s
if oranges_by_num.include? opposite
puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]]
puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]]
end
opposite = "0" + opposite
if oranges_by_num.include? opposite
puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]]
puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]]
end
end
oranges_by_num[vals[1]] = vals[0]
end
puts puzzles.length
puts puzzles.sample
File.open("wanderlust.txt", "w") do |f|
puzzles.each do |puzzle|
f.write("#{puzzle[0]}\n#{puzzle[1]}\n")
end
end
|