3 ms·
Great, in your distaste for the method that can involve knuckles, you have recreated it exactly. 1. alternate 31 and 30 2. reset in month 8 3. alter feb
by Dylan16807 12y ago
Great, in your distaste for the method that can involve knuckles, you have recreated it exactly.
1. alternate 31 and 30
2. reset in month 8
3. alter feb to 28
In my mind using modulus and floor in a mathematical formula is no more valid than using cases. A clever formula would avoid all of them.
- danbruc 12y agoROUND((61 + COS(3 * month - 22.5)) / 2) Admittedly rounding is still cheating but it allows compacter solutions than being spot-on every time. Handling February is left as an exercise for the reader.
- jcrites 12y ago> In my mind using modulus and floor in a mathematical formula is no more valid than using cases Agreed. Using floor it seems like you can construct a function that's effectively defined piecewise, by constructing a floor expression that's zero outside of a specified input domain, and 1 within the domain. Then you multiply the floor expression by the piecewise expression that you'd use to define a piecewise function over that domain. Nevertheless I found the article to be an interesting read on mathematical reasoning - a thought process for designing functions with particular behavior. Is there a rigorous way of describing why mod and floor seem like cheating in a way, aside from the fact that they can be used to construct piecewise functions? Is the ideal hack in this scenario a continuous, smooth function? (And something more interesting than the result of polynomial interpolation?)
- thaumasiotes 12y ago> Using floor it seems like you can construct a function that's effectively defined piecewise, by constructing a floor expression that's zero outside of a specified input domain, and 1 within the domain. Then you multiply the floor expression by the piecewise expression that you'd use to define a piecewise function over that domain. And you can fit a polynomial the same way by (using the example at hand) defining f(x) = c_1(x-2)(x-3)...(x-12) + c_2(x-1)(x-3)...(x-12) + c_3(x-1)(x-2)...(x-12) [but the (x-3) factor is missing!] + . . . + . . . + . . . + c_12(x-1)(x-2)...(x-11) And then choosing c_1 such that the c_1 term is equal to 31 when x=1, c_2 such that the c_2 term is equal to 28 when x=2, and so forth. You'll get a well-defined polynomial, impeccably "mathematical" -- in fact, you should get the polynomial listed in Someone's comment (since there should only be one 11th-degree polynomial passing through those 12 points). The traditional way to fit a polynomial to points is by reducing a matrix, linear-algebra style, but this approach is equivalent and, as you can see, amounts to nothing more than defining several functions which are zero except at the point of interest, and then scaling them to take the proper value at the point of interest. Why is that more "valid" than using a modulus? Frankly, I'm much more concerned by the OP using "2 mod x" when 1 is a legal value for x.