TAK.frink

Download or view TAK.frink in plain text format


// Benchmark of the TAK function:
// http://shootout.alioth.debian.org/benchmark.php?test=takfp&lang=all&sort=fullcpu
// This is a very recursive function that tests function calls and
// floating-point math.  Since Frink (currently) always uses
// arbitrary-precision floating-point math, this program will certainly be
// slow.  It's an interesting, and simple benchmark, though.

TAK[x,y,z] :=  y < x ? TAK[TAK[x-1.,y,z],TAK[y-1.,z,x],TAK[z-1.,x,y]] : z

TAK[n] :=
{
   start = now[]
   res = TAK[n*3., n*2., n*1.]
   end = now[]

   println["TAK[$n]:"];
   println[" Elapsed time: " + (end-start -> "seconds")]
   println[" Result: $res"]
}

for n = 7 to 10
   TAK[n]

   


Download or view TAK.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20145 days, 7 hours, 4 minutes ago.