99 problems in Haskell - Part 1 (Lists)

1.  myLast :: [a] -> a

    Find the last element of a list. Assume the list is non empty.

2.  myButLast :: [a] -> a

    Find the last but one element of a list. Assume the list has, at
    least, two elements.

3.  elementAt :: Int -> [a] -> a

    Find the k-th element of a list. The first element in the list is
    number 1. Assume the list has, at least, k elements.

4.  myLength :: [a] -> Int

    Find the number of elements of a list.

5.  myReverse :: [a] -> [a]

    Reverse a list.

6.  isPalindrome :: (Eq a) => [a] -> Bool

    Find out whether a list is a palindrome.

7.  myFlatten :: [[a]] -> [a]

    Flatten a two-level nested list structure.

8.  compress :: (Eq a) => [a] -> [a]

    Eliminate consecutive duplicates of list elements.

9.  pack :: (Eq a) => [a] -> [[a]]

    Pack consecutive duplicates of list elements into sublists. If a
    list contains repeated elements they should be placed in separate
    sublists.

10. encode :: (Eq a) => [a] -> [(Int, a)] 

    Run-length encoding of a list. Consecutive duplicates of elements
    are encoded as lists (n, e) where n is the number of duplicates of
    the element e.

Scoring

Each item scores 10 points.

Problem information

Author: Jordi Petit

Generation: 2026-02-03T16:59:20.681Z

© Jutge.org, 2006–2026.
https://jutge.org
