blob: dadd1f1a9c39fa0ae6619414b6fa2fa91137acde (
plain)
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
|
#!/usr/bin/ruby
#
# See ../README.md
#
#
# Run as: ruby ch-1.rb < input-file
#
#
# For a description of the algorithm, and the proof why this is correct:
# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-113-1.html
#
gcds = [0, 1, 2, 1, 2, 5, 2, 1, 2, 1]
ARGF . each_line do
| line |
n, d = line . split
n = n . to_i
d = d . to_i
if d == 0
puts (n >= 100 || n % 10 == 0 ? 1 : 0)
next
end
if n >= d * 10
then puts (1)
next
end
done = false
for i in 0 .. d / gcds [d] - 1 do
t = n - 10 * i - d
if t >= 0 && t % d == 0
then puts (1)
done = true
break
end
end
if not done
then puts (0)
end
end
|