Previously on BeamBA…

Fede presented the erlings

Run-length encoding of a list

Implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as terms [N, E] where N is the number of duplicates of the element E.

1> lists_exercises:run_length_encode(
    [a,a,a,a,b,c,c,a,a,d,e,e,e,e]).
%%[[4,a],[1,b],[2,c],[2,a],[1,d],[4,e]]

Brujo

showed

a solution

-module old.
-export [r/1].

r([]) -> [];
r([X|Xs]) -> r(X, r(Xs)).

r(X, [[C,X]|Xs]) -> [[C+1, X]|Xs];
r(X, Xs) -> [[1, X] | Xs].

Brujo's Idea 🧙‍♂️

People were confused

In order to understand recursion, one must first understand recursion.

-Donald Knuth (maybe?)

Plan for Today

  • Recursion over Lists
    • pattern-matching
    • auxiliary functions
  • Recursion over Maps
    • pattern-matching / guards
    • limitations
  • Higher-order functions
    • map
    • fold
\downarrow
\downarrow

Whatever you do,

you should never do

LIVE CODING!

- Chad DePue

SPAWNFEST

24-25/11

Una Charla Recurrente

By Brujo Benavides

Una Charla Recurrente

Una recurrente charla sobre recursión.

  • 80
Loading comments...

More from Brujo Benavides