3 ms·
I don't entirely like his generalized fizz buzz (with the printers and such), because it doesn't capture the way I read the requirements well. The requirements
by tetha 14y ago
I don't entirely like his generalized fizz buzz (with the printers and such), because it doesn't capture the way I read the requirements well.
The requirements to me read as: I have pairs of number-sets and strings, and whenever a number is divisible by all numbers in the set, the application is supposed to output the associated string. If multiple sets of numbers fulfill this property, the string associated with the largest set is used. If no group matches, output the number. Note that this specification contains a loophole: What if one set is [1, 2] and the other set is [2, 4] and the number is 4? This is undefined.
From such a data structure, deriving the generalized program is rather simple and straightforward and from there, I don't entirely see the reason to go nuts with functional programming and category theory and whatsoever, because the generalized solution is a rather simple folding operation and the biggest complications come from the hole in the spec.