[ create a new paste ] login | about

Link: http://codepad.org/dc1I9b23    [ raw code | output | fork ]

Haskell, pasted on Jun 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
import Char
main = putStrLn $ digitList 6

digitList n = unlines . map dashify . halfMap reverse $ explode
  where
    explode = reverse . take n . iterate tail . map intToDigit . reverse $ [1..n]
    halfMap f [] = []
    halfMap f (x:xs) = f x : halfMapDud f xs
    halfMapDud f [] = []
    halfMapDud f (x:xs) = x : halfMap f xs
    dashify [] = []
    dashify (x:[]) = x:[]
    dashify (x:xx:xs) = x:'-':dashify (xx:xs)


Output:
1
2
3
4
5
6
7
1
2-1
1-2-3
4-3-2-1
1-2-3-4-5
6-5-4-3-2-1



Create a new paste based on this one


Comments: