[ create a new paste ] login | about

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

Haskell, pasted on Apr 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
main = putStrLn (pechat' 1 6)

pechat' x n = 
    if x > n then "" else ((posledovatelnost' 1 x (x `mod` 2 == 0)) ++ "\n" ++ (pechat' (x+1) n))

posledovatelnost' x n zadomNapered = 
    if (x < n) then
        if zadomNapered then
           show n ++ "-" ++ (posledovatelnost' x (n-1) True)
           else
              show x ++ "-" ++ (posledovatelnost' (x+1) n False)
    else 
        if (x == n) then
           if zadomNapered then (show n) else (show x)
           else
               ""


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: