過去ログ

「数学」小旅行
wxMaxima で、1から5の場合をプログラムしてみました。(以下の通り)
実行結果、316.5秒で答えが出ました。
CPUはIntel(R)Core(TM)i5-4200M CPU @2.50GHz です。稼働率は25%。

しかし、1から6の場合を計算するには、もっと工夫しないと・・・
数百時間もかかりそうです(^^;;

/* [wxMaxima: input start ] */
x:0;count:0;
y:5;k:matrix([0,0,0,0,0]);
for a:1 step 1 while a<=y do
for b:1 step 1 while b<=y do
if a#b then
for c:1 step 1 while c<=y do
if a#c and b#c then
for d:1 step 1 while d<=y do
if a#d and b#d and c#d then
for e:1 step 1 while e<=y do
if a#e and b#e and c#e and d#e then
(k:addrow(k,[a,b,c,d,e]),x:x+1);

x:x+1;
for a:2 step 1 while a<=x do
for b:2 step 1 while b<=x do
if a#b and
not member(0,(row(k,a)-row(k,b))[1]) then
for c:2 step 1 while c<=x do
if a#c and b#c and
not member(0,(row(k,b)-row(k,c))[1]) and
not member(0,(row(k,c)-row(k,a))[1]) then
for d:2 step 1 while d<=x do
if a#d and b#d and c#d then
if not member(0,(row(k,a)-row(k,d))[1]) and
not member(0,(row(k,b)-row(k,d))[1]) and
not member(0,(row(k,c)-row(k,d))[1]) then
count:count+1;
/* [wxMaxima: input end ] */
   6月28日(土) 10:33:15     42007

過去問題一覧へ戻る