-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp043-substringdiv.rb
More file actions
40 lines (38 loc) · 817 Bytes
/
p043-substringdiv.rb
File metadata and controls
40 lines (38 loc) · 817 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
28
29
30
31
32
33
34
35
36
37
38
39
40
@answer = 0
def gen(ary,options,used,maxlen)
case ary.length
when 1
if ary[0].to_i==0 ; return end
when 4
if ary[1..-1].join.to_i.odd? ; return end
when 5
if ary[2..-1].join.to_i%3!=0 ; return end
when 6
if ary[3..-1].join.to_i%5!=0 ; return end
when 7
if ary[4..-1].join.to_i%7!=0 ; return end
when 8
if ary[5..-1].join.to_i%11!=0 ; return end
when 9
if ary[6..-1].join.to_i%13!=0 ; return end
when 10
if ary[7..-1].join.to_i%17!=0 ; return end
end
if ary.length==maxlen
@answer += ary.join.to_i
return
end
usable=options-used
usable.each { |i|
ary.push(i)
used.push(i)
gen(ary,options,used,maxlen)
ary.delete(i)
used.delete(i)
}
end
options=(0..9).to_a
result=[]
used=[]
gen(result,options,used,options.length)
puts @answer