diff options
Diffstat (limited to 'generate_orange.rb')
-rw-r--r-- | generate_orange.rb | 56 |
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 @@ | |||
1 | require 'sqlite3' | ||
2 | |||
3 | db = SQLite3::Database.open ARGV[0] | ||
4 | form_rows = db.query "SELECT form FROM forms WHERE proper = 0" | ||
5 | |||
6 | wanderlust = {} | ||
7 | wanderlust["w"] = "1" | ||
8 | wanderlust["a"] = "2" | ||
9 | wanderlust["n"] = "3" | ||
10 | wanderlust["d"] = "4" | ||
11 | wanderlust["e"] = "5" | ||
12 | wanderlust["r"] = "6" | ||
13 | wanderlust["l"] = "7" | ||
14 | wanderlust["u"] = "8" | ||
15 | wanderlust["s"] = "9" | ||
16 | wanderlust["t"] = "0" | ||
17 | |||
18 | forms = form_rows.map {|row| row[0].downcase} | ||
19 | orange_forms = forms.reject {|form| /^[wanderlust]*$/.match(form).nil?}.select {|form| form.length >= 3} | ||
20 | words = orange_forms.map do |form| | ||
21 | oranged = form.chars.map {|letter| wanderlust[letter]}.join | ||
22 | [form, oranged, oranged.to_i] | ||
23 | end | ||
24 | words.sort_by! {|word| word[2]} | ||
25 | |||
26 | puts words.length | ||
27 | puts words[10] | ||
28 | puts words.sample | ||
29 | puts "" | ||
30 | |||
31 | oranges_by_num = {} | ||
32 | puzzles = [] | ||
33 | words.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] | ||
47 | end | ||
48 | |||
49 | puts puzzles.length | ||
50 | puts puzzles.sample | ||
51 | |||
52 | File.open("wanderlust.txt", "w") do |f| | ||
53 | puzzles.each do |puzzle| | ||
54 | f.write("#{puzzle[0]}\n#{puzzle[1]}\n") | ||
55 | end | ||
56 | end | ||