-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
53 lines (43 loc) · 1.18 KB
/
main.rb
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
require_relative 'pokedex'
require_relative 'pokeset'
@start_time = Time.now
ALPHABET = 2**26 - 1
@dex = Pokedex.new(ARGV[0] || 'pokemon.txt')
@min_set = Pokeset.new(@dex.all)
def room_for_two_more(set)
set.length + 1 < @min_set.length
end
def room_for_one_more(set)
(set.length + 1 == @min_set.length && (set.total_length + set.missing_char_count) <= @min_set.total_length)
end
def new_min_set(set)
@min_set = set
puts "new min_set: #{set}, found in #{Time.now - @start_time} seconds"
end
def add_next_to_set(orig_set)
@dex.map[(@dex.chars_order - orig_set.chars)[0]].each do |pokemon|
new_set = Pokeset.new(orig_set.set + [pokemon])
if new_set.code == ALPHABET
if new_set <= @min_set
new_min_set(new_set)
else
next
end
elsif room_for_two_more(new_set) || room_for_one_more(new_set)
add_next_to_set(new_set)
else
next
end
end
end
threads = []
@dex.map[@dex.chars_order[0]].each do |pokemon|
threads << Thread.new do
set = Pokeset.new([pokemon])
if set.code < ALPHABET
add_next_to_set(set)
end
end
end
threads.each{|t| t.join}
puts "min_set: #{@min_set}, found in #{Time.now - @start_time} seconds"