{-
?????????: Recursion / Divide and Conquer - Koch Curve
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
?????°:
19:13:58 ?????°??¨????????°Haskell???Haskell??¨????????°?????°???????????????????????¨????????°Haskell?????????????????£?????????????????????
19:26:43 ????????????????\????????????????????????????????´???°???
19:27:43 ??¨??????????????????????????????
19:30:18 ????´???°?????????
19:33:48 ????????????
-}
import Control.Applicative
import Control.Monad
import Data.Complex


main = do
 n <- fmap read getLine
 forM_ (koch n) $ \(x:+y) -> putStrLn (show x ++ " " ++ show y)

type Coor = Complex Double

koch :: Int -> [Coor]
koch 0 = [(0:+0), (100:+0)]
koch n = interweave foo $ koch (n-1)

foo :: Coor -> Coor -> [Coor]
foo p1 p2 = [p1+vec, p1 + vec + vec * cis (pi/3) , p2-vec] where vec = (p2-p1)/3

-- interweave f [a,b,c] ==  [a] ++ a `f` b ++ [b] ++ b `f` c ++ [c]
interweave :: (a -> a -> [a]) -> [a] -> [a]
interweave _ [u] = [u]
interweave f (a:b:cs) = [a] ++ a `f` b ++ interweave f (b:cs)