2015年12月31日木曜日

151231(7)

Ruby


Numbers that are not the sum of distinct pentagonal numbers

オンライン整数列大辞典の
A121405(http://oeis.org/A121405/list)
と比較し、答え合わせしてみる。

def A121405()
  # 177以上の自然数は異なる五角数の和で表されることが証明できているものとする
  ary = (1..11).map{|i| i * (3 * i - 1) / 2}
  a_ary = []
  (1..ary.size).each{|i|
    ary.combination(i){|c|
      a_ary << c.inject(:+)
    }
  }
  (1..176).to_a - a_ary.uniq
end
ary = A121405()

# OEIS A121405のデータ
ary0 =
[2,3,4,7,8,9,10,11,14,15,16,19,20,21,24,25,26,29,
 30,31,32,33,37,38,42,43,44,45,46,49,50,54,55,59,
 60,61,65,66,67,72,77,80,81,84,89,94,95,96,100,101,
 102,107,112,116,124,136,137,141,142,147,159]
# 一致の確認
p ary == ary0

0 件のコメント:

コメントを投稿

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