23
3

More than 3 years have passed since last update.

# Elixirで竹内関数を計測してみた

Last updated at Posted at 2020-12-18

この記事は Elixir Advent Calendar 2020 19日目の記事です。

## 竹内関数

tarai(x,y,z) =
\left\{
\begin{array}{lll}
y & \textrm{if} & x \leq y\\
tarai(tarai(x-1,y,z), tarai(y-1,z,x), tarai(z-1,x,y)) & \textrm{else} &
\end{array}
\right.


## Elixirで実装

defmodule Takeuchi do
def tarai(x,y,_) when x <= y do
y
end
def tarai(x, y, z) do
tarai(tarai(x-1,y,z), tarai(y-1,z,x), tarai(z-1,x, y))
end
end


iex(1)> :timer.tc(Takeuchi, :tarai, [10,5,0])
{15000, 10}
iex(2)> :timer.tc(Takeuchi, :tarai, [12,6,0])
{156000, 12}
iex(3)> :timer.tc(Takeuchi, :tarai, [14,7,0])
{7234000, 14}
iex(4)> :timer.tc(Takeuchi, :tarai, [16,8,0])
{503249780, 16}
iex(5)> :timer.tc(Takeuchi, :tarai, [18,9,0])
{29903428454, 18}


23
3
0

Register as a new user and use Qiita more conveniently

1. You get articles that match your needs
2. You can efficiently read back useful information
3. You can use dark theme
What you can do with signing up
23
3