Comment by javcasas
2 days ago
So a tree is easier to do recursing vs iterating in some cases, whereas in other cases recursion and iteration have roughly the same level of complexity.
Kinda shows that recursive data structures are usually better dealt with recursion. Worst case you end up with the same level of difficulty as iteration.
My career is practically built on the fact that other people 99% of the miss the simplest representation of the data/problem.
Just look at myriad ways that people implement something like checking win conditions in Rock, Paper, Scissors. Switch statements, conditional hell, etc.
...you can just do something as simple as stick Rock, Scissors, Paper into a circular list and compare to the next element. It's practically readable as plain English. No programming skill required.
If you need to code golf you can use modulo arithmetic, for a different kind of "simple", but then you lose readability.
You could have a big pattern-match statement for Rock, Scissors, Paper and it would still be readable (in a language that supports these things like eg Rust).
The circular list seems a bit too cute for me. Sure, it's possible, but seems like overkill.
If you have to do a bunch of list manipulation yourself sure but most scripting languages make these things trivial.
Heck, you could easily write it using Terraform built-in functions.
1 reply →