2015-05-19から1日間の記事一覧
バイナリカウント問題解いてみた。提出コードはこんな感じ。 # 平易で遅い計算。テスト用。 def solve_slow(x) (1..x).inject(0) do |acc,x| acc+x.to_s(2).count("1") end end # F(x) の xが奇数の場合のアルゴリズム。 def solve_odd( x ) (x+1)/2 + 2*sol…
バイナリカウント問題解いてみた。提出コードはこんな感じ。 # 平易で遅い計算。テスト用。 def solve_slow(x) (1..x).inject(0) do |acc,x| acc+x.to_s(2).count("1") end end # F(x) の xが奇数の場合のアルゴリズム。 def solve_odd( x ) (x+1)/2 + 2*sol…