blob: 6aee8ec9b43fb567b096c28ed8ee427765103537 (
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
|
#!/usr/bin/bc
#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-147
#
#
# Run as: bc ch-2.bc
#
define is_pentagonal (p) {
auto l, h, m
l = l
h = high
while (l <= h) {
m = (l + h) / 2
if (pentagon [m] == p) {return 1}
if (pentagon [m] < p) {l = m + 1} else {h = m - 1}
}
return 0
}
while (!done) {
p = p + n + n + n + 1
n = n + 1
high = high + 1
pentagon [high] = p
for (i = 1; i <= high && pentagon [i] + pentagon [i] < p && !done; i ++) {
seen = pentagon [i]
if (is_pentagonal (p - seen) && is_pentagonal (p - seen - seen)) {
print seen, " "
p - seen
done = 1
}
}
}
halt
|