15. Exercises

Exercise 01

Find the last element of a list.

* (my-last '(a b c d))
(D)

Solution

Exercise 02

Find the last and second-to-last element of a list.

* (my-but-last '(a b c d))
(C D)

Solution

Exercise 03

Find an element by its position, with 1 being the first element.

* (element-at '(a b c d e) 3)
C

Solution

Exercise 04

Calculate the number of elements in a list.

* (my-length '(a b c d e))
5

Solution

Exercise 05

Reverse a list.

* (my-reverse '(a b c d e))
(E D C B A)

Solution

Exercise 06

Tell whether a list is a palindrome (it reads the same from left to right as from right to left).

* (palindromep '(a b c b a))
T

The letter p at the end of the function name indicates that it returns a boolean value (true/false).

Solution

Exercise 07

Flatten a list. To do this you will need to traverse each list recursively, replacing it with an element.

* (my-flatten '(a (b (c d) e)))
(A B C D E)

Solution

Exercise 08

Remove consecutive duplicate elements from the list. If a list contains repeated elements, they should be replaced with a single copy of the element. The order of the elements should not be changed.

* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)

This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.

Desafíos de programación atemporales y multiparadigmáticos

Desafíos de programación atemporales y multiparadigmáticos

Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.

Buy the book

Will you buy me a coffee?

This is how I keep writing without ads or paywalls.

Comments

There are no comments yet.