By Leonardo Giordani Published on Last update on

I decided to learn Scala. I looked for some good exercises for Scala programmers and found S-99: Ninety-Nine Scala Problems, and since writing about things helps me learning them I am going to write a post for each problem I manage to solve.

The official site provides solutions for the problems, so my solutions will obviously be influenced by those, when not the same.

CAVEAT: I am a beginner so what I state in the following posts may be inaccurate and sometimes wrong. Please submit an issue on the blog GitHub issues page.

This is the index of the problems I already discussed. I kept the original title and difficulty ranking (asterisks)

• P01 (*) Find the last element of a list.
• P02 (*) Find the last but one element of a list.
• P03 (*) Find the Kth element of a list.
• P04 (*) Find the number of elements of a list.
• P05 (*) Reverse a list.
• P06 (*) Find out whether a list is a palindrome.
• P07 (**) Flatten a nested list structure.
• P08 (**) Eliminate consecutive duplicates of list elements.
• P09 (**) Pack consecutive duplicates of list elements into sublists.
• P10 (*) Run-length encoding of a list.
• P11 (*) Modified run-length encoding.
• P12 (**) Decode a run-length encoded list.
• P13 (**) Run-length encoding of a list (direct solution).
• P14 (*) Duplicate the elements of a list.
• P15 (**) Duplicate the elements of a list a given number of times.
• P16 (**) Drop every Nth element from a list.
• P17 (*) Split a list into two parts.
• P18 (**) Extract a slice from a list.
• P19 (**) Rotate a list N places to the left.
• P20 (*) Remove the Kth element from a list.