-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem32.rb
More file actions
27 lines (26 loc) · 722 Bytes
/
problem32.rb
File metadata and controls
27 lines (26 loc) · 722 Bytes
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
require("./utils")
class Problem32
def Problem32.run
pandigitals = Utils.get_pandigitals(9)
products = []
pandigitals.each do |p|
string_p = String(p)
part_one = string_p[0..1]
part_two = string_p[2..4]
part_three = string_p[5..9]
if Integer(part_one) * Integer(part_two) == Integer(part_three)
products << Integer(part_three)
end
end
pandigitals.each do |p|
string_p = String(p)
part_one = string_p[0..0]
part_two = string_p[1..4]
part_three = string_p[5..9]
if Integer(part_one) * Integer(part_two) == Integer(part_three)
products << Integer(part_three)
end
end
puts products.uniq.inject(:+)
end
end