The space time complexity tradeoff
I encountered a neat example recently while solving Advent of Code 2015, day 6. The problem can be boiled down to "There is a 2D array of values. Given a range and instruction, apply the instruction to all values in that range. How many values are 'on' at the end?". There are only 2 possible states for each value: on and off, and only 3 possible instructions: on, off, and toggle. I won't focus too much on parsing the input or the structure of the algorithm here, I just want to investigate the hot loop which applies the instruction to each value.