2018年10月15日月曜日

181015

Ruby


A320387, A320385, A007294 とA179269

n が100以下のとき、出力してみた。

@ary1 = [1]
@ary2 = [1]
@ary3 = [1]
@ary4 = [1]

def partition(n, min, max)
  return [[]] if n == 0
  [max, n].min.downto(min).flat_map{|i| partition(n - i, min, i - 1).map{|rest| [i, *rest]}}
end

# n > 0
def f(n)
  cnt1, cnt2, cnt3, cnt4 = 0, 0, 0, 0
  partition(n, 1, n).each{|ary|
    ary << 0
    ary0 = (1..ary.size - 1).map{|i| ary[i - 1] - ary[i]}
    ary1 = ary0.sort
    if ary1 == ary0
      cnt1 += 1
      cnt2 += 1 if ary0.uniq == ary0
    end
    if ary1 == ary0.reverse
      cnt3 += 1
      cnt4 += 1 if ary0.uniq == ary0
    end
  }
  @ary1 << cnt1
  @ary2 << cnt2
  @ary3 << cnt3
  @ary4 << cnt4
end

n = 100
(1..n).each{|i| f(i)}
puts "A320387"
p @ary1
puts "A320385"
p @ary2
puts "A007294"
p @ary3
puts "A179269"
p @ary4

出力結果
A320387
[1, 1, 1, 2, 1, 2, 3, 2, 2, 4, 3, 4, 5, 3, 5, 7, 4, 7, 8, 6, 8, 11, 7, 9, 13, 9, 11, 16, 12, 15, 18, 13, 17, 20, 17, 21, 24, 19, 24, 30, 22, 28, 34, 26, 34, 38, 30, 37, 43, 37, 42, 48, 41, 50, 58, 48, 55, 64, 53, 64, 71, 59, 73, 81, 69, 79, 89, 79, 90, 101, 87, 100, 111, 97, 115, 124, 108, 126, 137, 121, 140, 152, 138, 151, 169, 151, 166, 185, 167, 191, 201, 182, 206, 220, 204, 228, 243, 222, 250, 268, 243]
A320385
[1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 2, 3, 2, 3, 4, 3, 3, 5, 3, 5, 6, 4, 5, 7, 5, 7, 8, 6, 7, 10, 8, 9, 11, 8, 11, 13, 9, 13, 15, 12, 14, 17, 13, 16, 20, 15, 18, 22, 18, 21, 25, 20, 23, 27, 23, 28, 30, 26, 30, 34, 30, 33, 38, 31, 38, 43, 36, 42, 46, 42, 47, 50, 45, 50, 58, 51, 55, 61, 56, 64, 68, 60, 68, 74, 70, 75, 80, 74, 82, 89, 82, 89, 96, 90, 99, 104, 97, 108, 114, 107, 116]
A007294
[1, 1, 1, 2, 2, 2, 4, 4, 4, 6, 7, 7, 10, 11, 11, 15, 17, 17, 22, 24, 25, 32, 35, 36, 44, 48, 50, 60, 66, 68, 81, 89, 92, 107, 117, 121, 141, 153, 159, 181, 197, 205, 233, 252, 262, 295, 320, 332, 372, 401, 417, 465, 501, 520, 575, 619, 645, 710, 763, 793, 869, 933, 971, 1059, 1134, 1180, 1286, 1374, 1430, 1549, 1654, 1722, 1863, 1985, 2065, 2225, 2372, 2467, 2654, 2821, 2934, 3149, 3345, 3478, 3724, 3949, 4109, 4391, 4652, 4835, 5157, 5460, 5676, 6043, 6390, 6638, 7059, 7457, 7747, 8220, 8676]
A179269
[1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 5, 5, 5, 7, 7, 7, 10, 10, 10, 13, 14, 14, 18, 19, 19, 23, 25, 25, 30, 32, 33, 38, 41, 42, 48, 52, 54, 60, 65, 67, 75, 81, 84, 92, 99, 103, 113, 121, 126, 136, 147, 153, 165, 177, 184, 197, 213, 221, 236, 253, 264, 280, 301, 313, 331, 355, 371, 390, 418, 435, 458, 490, 511, 535, 571, 595, 624, 665, 693, 723, 771, 803, 838, 891, 928, 966, 1028, 1070, 1113, 1180, 1230, 1277, 1354, 1409, 1462, 1547, 1612, 1670, 1766, 1837, 1904]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。