0hc.net Menu
Home Overview
About Menu
Impressum

Polygons

Use a group of dots to represent a certain number, then they can be arranged in geometrical figures. For example a triangle: T1 T2 T3 # # # # # # # # # # How many dots are in such a polygon? Haskell: -- Triangular Numbers module Main where main :: IO () main = mapM_ print $ tri [1..100] tri :: Integral a => [a] -> [(a,a)] tri l = map (\i -> (i,(i*(i+1))`div`2)) l -- Polygonial Numbers module Main where main :: IO () main = mapM_ print $ fPo [3..6] [1..10] fPo :: Fractional a => [a] -> [a] -> [(a,a)] fPo l1 l2 = [(r, (i/2)*((i-1)*r-2*(i-2)) ) | r <- l1, i <- l2]
0hc.net    © 2001-2014 Harald Wolfsgruber