-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
91 lines (73 loc) · 2.38 KB
/
prog.sf
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/ruby
# a(n) is the smallest n-gonal pyramidal number which can be represented as the sum of n distinct nonzero n-gonal pyramidal numbers in exactly n ways, or -1 if none exists.
# https://oeis.org/A359321
# For n = 3: 2300 = 1 + 969 + 1330 = 56 + 220 + 2024 = 165 + 364 + 1771.
# For n = 4: 6201 = 1 + 91 + 1785 + 4324 = 1 + 285 + 1015 + 4900 = 30 + 140 + 506 + 5525 = 91 + 819 + 1496 + 3795.
# Known terms:
# 2300, 6201, 8125, 6391
# Conjecture:
# a(7)-a(11) are all -1.
func isok(index, k) {
var n = index.pyramidal(k)
var arr = (1..^index -> map{|j| pyramidal(j, k) })
var s = Set(arr...)
var sol = []
arr.combinations(k-1, {|*a|
with (n - a.sum) {|d|
if (s.has(d) && !a.has(d)) {
sol << a
}
}
})
sol.map {|a| [a..., n - a.sum].sort }.uniq
}
func a(n) {
for k in (1..Inf) {
var sol = isok(k, n)
if (sol.len == n) {
return [n, k, k.pyramidal(n)]
}
elsif (sol.len > n) {
say "[#{n}] Found #{sol.len} solutions for k = #{k}..."
}
}
}
for k in (3..6) {
say a(k)
}
#~ say a(12)
__END__
[7] Found 8 solutions for k = 22...
[7] Found 15 solutions for k = 26...
[7] Found 9 solutions for k = 27...
[7] Found 18 solutions for k = 28...
[7] Found 12 solutions for k = 29...
[7] Found 20 solutions for k = 30...
[7] Found 27 solutions for k = 31...
[7] Found 44 solutions for k = 32...
[7] Found 42 solutions for k = 33...
[7] Found 46 solutions for k = 34...
[7] Found 46 solutions for k = 35...
[7] Found 70 solutions for k = 36...
[7] Found 85 solutions for k = 37...
[7] Found 81 solutions for k = 38...
[7] Found 88 solutions for k = 39...
[8] Found 10 solutions for k = 23...
[8] Found 18 solutions for k = 24...
[8] Found 14 solutions for k = 25...
[8] Found 24 solutions for k = 26...
[8] Found 17 solutions for k = 27...
[8] Found 28 solutions for k = 28...
[8] Found 53 solutions for k = 29...
[9] Found 14 solutions for k = 26...
[9] Found 23 solutions for k = 27...
[9] Found 22 solutions for k = 28...
[9] Found 36 solutions for k = 29...
[10] Found 11 solutions for k = 26...
[10] Found 17 solutions for k = 27...
[10] Found 11 solutions for k = 28...
[10] Found 34 solutions for k = 29...
[11] Found 12 solutions for k = 27...
[11] Found 15 solutions for k = 29...
[11] Found 32 solutions for k = 30...
[12] Found 33 solutions for k = 31...