News for hackers. Stuff that matters.
Re:Oh, Go Ahead, Overthink FizzBuzz (2008) by ilurk on Thursday November 19, 2015 @04:00PM (#10597625)
Could you explain these lines:

> int (* PC[15])(int i) = { i,i,f,i,b,f,i,i,f,b,i,f,i,i,fb }; // Printer Cycle

> int (* LC[2]) (int index) = { go, stop }; // Logic Cycle

I can see they behave as functions, but I don't understand what exactly are they or the logic that makes then work.

Re:Oh, Go Ahead, Overthink FizzBuzz (2008) by cronin101 on Thursday November 19, 2015 @04:14PM (#10597730)
I can try!

They are both an array of pointers to functions.

Go(int i) is a function that finds the correct "printer" for a number, i, within the cycle of 15. `Go` then calls the printer function with the argument and prints the corresponding line.

Stop(int i) has similar side-effect but exits immediately after.

Since all of the printers return the value of "i", you can recursively call them in cycle-sequence through `go` until the return value lines up with the "kill number" and causes `stop` to be called instead (this works as `i % n > 0` for all numbers below n and you can force this to be zero, and thus index the first element of the array, by negating it).

Sorry for the scatterbrained explanation, the code wasn't designed to be particularly comprehensible!