summary refs log tree commit diff stats
path: root/generate_orange.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-12-10 16:45:29 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2022-12-10 16:45:29 -0500
commit807b1f049bcc4597400eea21228875efe098ebc5 (patch)
tree1e7a87187a616f0488822b1750c1b30b7e84a97d /generate_orange.rb
parentdad0c0c6dc5a6c04f305f71ed78ca99f85cca78c (diff)
downloadlingo-807b1f049bcc4597400eea21228875efe098ebc5.tar.gz
lingo-807b1f049bcc4597400eea21228875efe098ebc5.tar.bz2
lingo-807b1f049bcc4597400eea21228875efe098ebc5.zip
Added orange puzzles
fixes #23
Diffstat (limited to 'generate_orange.rb')
-rw-r--r--generate_orange.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/generate_orange.rb b/generate_orange.rb new file mode 100644 index 0000000..310f823 --- /dev/null +++ b/generate_orange.rb
@@ -0,0 +1,56 @@
1require 'sqlite3'
2
3db = SQLite3::Database.open ARGV[0]
4form_rows = db.query "SELECT form FROM forms WHERE proper = 0"
5
6wanderlust = {}
7wanderlust["w"] = "1"
8wanderlust["a"] = "2"
9wanderlust["n"] = "3"
10wanderlust["d"] = "4"
11wanderlust["e"] = "5"
12wanderlust["r"] = "6"
13wanderlust["l"] = "7"
14wanderlust["u"] = "8"
15wanderlust["s"] = "9"
16wanderlust["t"] = "0"
17
18forms = form_rows.map {|row| row[0].downcase}
19orange_forms = forms.reject {|form| /^[wanderlust]*$/.match(form).nil?}.select {|form| form.length >= 3}
20words = orange_forms.map do |form|
21 oranged = form.chars.map {|letter| wanderlust[letter]}.join
22 [form, oranged, oranged.to_i]
23 end
24words.sort_by! {|word| word[2]}
25
26puts words.length
27puts words[10]
28puts words.sample
29puts ""
30
31oranges_by_num = {}
32puzzles = []
33words.each do |vals|
34 oranges_by_num.each do |num, form|
35 opposite = (vals[2] - num.to_i).to_s
36 if oranges_by_num.include? opposite
37 puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]]
38 puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]]
39 end
40 opposite = "0" + opposite
41 if oranges_by_num.include? opposite
42 puzzles << ["#{form} + #{oranges_by_num[opposite]}", vals[0]]
43 puzzles << ["#{oranges_by_num[opposite]} + #{form}", vals[0]]
44 end
45 end
46 oranges_by_num[vals[1]] = vals[0]
47end
48
49puts puzzles.length
50puts puzzles.sample
51
52File.open("wanderlust.txt", "w") do |f|
53 puzzles.each do |puzzle|
54 f.write("#{puzzle[0]}\n#{puzzle[1]}\n")
55 end
56end