過去ログ

「数学」小旅行
一般化をしたプログラムを作ってみましたが、7の3ぐらいになると時間がかかってしまいます。もっといいやり方があるのでしょうか。
n=7;m=3
n2=n/2
a=(-n2..n2).to_a;if n%2==0 then a=a-[0] end
b=a.repeated_permutation(2).to_a.combination(m).to_a
c=a.repeated_permutation(2).to_a.combination(m).to_a
s=c.size

for t in b
  ts=t.sort
   for i in 0..s-1
    if ts==c[i].map{|t|t.map{|u|-u}}.sort||ts==c[i].map{|t|[-t[1],t[0]]}.sort||ts==c[i].map{|t|[t[1],-t[0]]}.sort then
    c[i]=t
    end
   end
end

p c.uniq.size
   7月19日(水) 15:37:54     52621

過去問題一覧へ戻る