過去ログ

「数学」小旅行
Rubyでプログラムです。再帰呼び出しを使っています。

$n=0

def f(s,a)
s+=a
if s<=8 then
if s== 8 then
$n+=1
else
for i in [1,2,3]
if (a == 1) or (i != a) then
f(s,i)
end
end
end
end
end

f(-1,1)
p $n
   4月22日(木) 11:24:54     50417

過去問題一覧へ戻る