-- $Id: nestedloop.ghc,v 1.1 2001/02/22 23:22:11 doug Exp $ -- http://www.bagley.org/~doug/shootout/ -- from Brian Gregor module Main where import System(getArgs, exitWith, ExitCode(..)) import Numeric(readDec) main = do arg <- getArgs case arg of [number] -> let n = fst (head (readDec number)) in putStrLn (show (loopA n n 0)) _ -> exitWith (ExitFailure 1) loopA :: Int -> Int -> Int -> Int loopA n m x | n > 0 = loopA (n-1) m (loopB m m x) | otherwise = x loopB :: Int -> Int -> Int -> Int loopB n m x | n > 0 = loopB (n-1) m (loopC m m x) | otherwise = x loopC :: Int -> Int -> Int -> Int loopC n m x | n > 0 = loopC (n-1) m (loopD m m x) | otherwise = x loopD :: Int -> Int -> Int -> Int loopD n m x | n > 0 = loopD (n-1) m (loopE m m x) | otherwise = x loopE :: Int -> Int -> Int -> Int loopE n m x | n > 0 = loopE (n-1) m (loopF m x) | otherwise = x loopF :: Int -> Int -> Int loopF n x | n > 0 = loopF (n-1) (x+1) | otherwise = x