# Shootout/Takfp

### From HaskellWiki

< Shootout(Difference between revisions)

DonStewart (Talk | contribs) (moved) |
m |

## Latest revision as of 07:50, 13 December 2009

A ShootoutEntry for takfp

## [edit] 1 Shorter entry

Shortest entry in any language. Faster than old entry (by cranking up gcc)

{-# OPTIONS -O2 -optc-O3 #-} -- http://shootout.alioth.debian.org/ -- -- GHC version of floating point Tak function -- compile with ghc -O2 -fexcess-precision -o takfp takfp.hs -- contributed by Greg Buchholz, optimized by Einar Karttunen and Don Stewart import System main = print . (\n -> tak (3*n) (2*n) n) . read . head =<< getArgs tak x y z = if y>=x then z::Float else tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y)

## [edit] 2 Current entry

Refactor musasabi's code. Still uses too much space.

import System main = print . (\n -> tak (3*n) (2*n) n) . read . head =<< getArgs tak x y z | y >= x = z :: Float | otherwise = tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y)

## [edit] 3 Old entry

-- http://shootout.alioth.debian.org/ -- -- GHC version of floating point Tak function -- compile with ghc -O2 -fexcess-precision -o takfp takfp.hs -- contributed by Greg Buchholz, optimized by Einar Karttunen import System(getArgs) main = do n <- getArgs >>= readIO.head print $ tak (3*n) (2*n) n tak :: Float -> Float -> Float -> Float tak x y z | y>=x = z | otherwise = tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y)