-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem43.rb
More file actions
24 lines (22 loc) · 836 Bytes
/
problem43.rb
File metadata and controls
24 lines (22 loc) · 836 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
require("./utils")
class Problem43
def Problem43.run
good_ones = []
pandigitals = Utils.get_pandigitals(0, 9)
pandigitals.each do |x|
good_ones << x if check(x)
end
puts "Answer: #{good_ones.inject(:+)}"
end
def Problem43.check x
str_x = x.to_s
return false if Integer(Utils.strip_leading_zero(str_x[1..3])) % 2 != 0
return false if Integer(Utils.strip_leading_zero(str_x[2..4])) % 3 != 0
return false if Integer(Utils.strip_leading_zero(str_x[3..5])) % 5 != 0
return false if Integer(Utils.strip_leading_zero(str_x[4..6])) % 7 != 0
return false if Integer(Utils.strip_leading_zero(str_x[5..7])) % 11 != 0
return false if Integer(Utils.strip_leading_zero(str_x[6..8])) % 13 != 0
return false if Integer(Utils.strip_leading_zero(str_x[7..9])) % 17 != 0
true
end
end