Vel Tech exam 2018 P22600


Statement
 

pdf   zip

thehtml
  1. Write a function df :: Int -> Int that returns the double factorial of a natural number. The double factorial of n is denoted n!! and is n(n−2)(n−4)….
  2. Write a function sumd :: Int -> Int that returns the sum of the digits of a natural number.
  3. Write a function dup :: [Int] -> [Int] that duplicates each element in a list.
  4. Write a function pal :: String -> Bool that tells if a string is a palindrome, ie, if it is equal to its reverse.
  5. Write a function apply2 :: (a -> a) -> a -> a that applies a function twice to some parameter.
Public test cases
  • Input

    df 0
    df 1
    df 2
    df 3
    df 10
    df 11
    df 13
    

    Output

    1
    1
    2
    3
    3840
    10395
    135135
    
  • Input

    sumd 0
    sumd 3
    sumd 23
    sumd 999
    sumd 8756
    

    Output

    0
    3
    5
    27
    26
    
  • Input

    dup [1,2,3]
    dup []
    dup [666]
    dup [4,4,2,3,8,2]
    

    Output

    [1,1,2,2,3,3]
    []
    [666,666]
    [4,4,4,4,2,2,3,3,8,8,2,2]
    
  • Input

    pal "abcba"
    pal "xyzaz"
    pal ""
    pal "a"
    pal "aa"
    pal "aba"
    pal "abb"
    pal "abcdedcbz"
    

    Output

    True
    False
    True
    True
    True
    True
    False
    False
    
  • Input

    apply2 (+ 2.5) 10.5
    apply2 (* 3) 4
    apply2 ("hello " ++) "peter"
    

    Output

    15.5
    36
    "hello hello peter"
    
  • Information
    Author
    Jordi Petit
    Language
    English
    Official solutions
    Haskell
    User solutions
    Haskell