#/*********************************************************** # acker.rb -- Ackermann (アッカーマン) 関数 #***********************************************************/ $test = true $count = 0 def A( x, y) if ($test) $count += 1 end if (x == 0); return y + 1; end if (y == 0); return A(x - 1, 1); end return A(x - 1, A(x, y - 1)) end printf("A(3, 3) = %d\n", A(3, 3)) if ($test) printf("A(x, y) は %d 回呼び出されました.\n", $count) end exit 0