15. Exercises
Exercise 01
Find the last element of a list.
* (my-last '(a b c d))
(D)
Exercise 02
Find the last and second-to-last element of a list.
* (my-but-last '(a b c d))
(C D)
Exercise 03
Find an element by its position, with 1 being the first element.
* (element-at '(a b c d e) 3)
C
Exercise 04
Calculate the number of elements in a list.
* (my-length '(a b c d e))
5
Exercise 05
Reverse a list.
* (my-reverse '(a b c d e))
(E D C B A)
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
pat the end of the function name indicates that it returns a boolean value (true/false).
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)
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
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 bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.