-
Notifications
You must be signed in to change notification settings - Fork 0
/
irregular_triangle_of n AND k != k.sf
59 lines (47 loc) · 1.53 KB
/
irregular_triangle_of n AND k != k.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
#!/usr/bin/ruby
# Generate a nice sequence of numbers, generated by an irragular triangle, based on the logical binary equation:
# n AND k = k, where k are values in the range [1, n]
# See also:
# https://oeis.org/A038573
# https://oeis.org/A335063
# https://oeis.org/A048967
# Reading these irregular triangles by rows in a flat list,
# and plotting the list, generates the Sierpiński triangle.
# See also:
# https://en.wikipedia.org/wiki/Sierpiński_triangle
say ":: Irregular triangle of numbers n such that n AND k != k:\n"
var seq_neg_lens = []
var seq_neg_sums = []
for n in (1..20) {
var arr = (1..n -> grep {|k| n&k != k })
seq_neg_lens << arr.len
seq_neg_sums << arr.sum
say ("#{'%2d' % n}: ", arr)
}
say ''
say "Lens: #{seq_neg_lens}"
say "Sums: #{seq_neg_sums}"
__END__
:: Irregular triangle of numbers n such that n AND k != k:
1: []
2: [1]
3: []
4: [1, 2, 3]
5: [2, 3]
6: [1, 3, 5]
7: []
8: [1, 2, 3, 4, 5, 6, 7]
9: [2, 3, 4, 5, 6, 7]
10: [1, 3, 4, 5, 6, 7, 9]
11: [4, 5, 6, 7]
12: [1, 2, 3, 5, 6, 7, 9, 10, 11]
13: [2, 3, 6, 7, 10, 11]
14: [1, 3, 5, 7, 9, 11, 13]
15: []
16: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
17: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
18: [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17]
19: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
20: [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19]
Lens: [0, 1, 0, 3, 2, 3, 0, 7, 6, 7, 4, 9, 6, 7, 0, 15, 14, 15, 12, 17]
Sums: [0, 1, 0, 6, 5, 9, 0, 28, 27, 35, 22, 54, 39, 49, 0, 120, 119, 135, 114, 170]