Solution for Étude 7-3: Using lists:foldl/3