Okay, so I see a reoccuring minor problem I'm having. I'm given formulas people build using spreadsheets. Often the formula is something like this with a table:
roundup(0.04*(LV^2)+100)
which is fine in itself. The problem is there's often a special case for the first element that doesn't fit in the formula. For example the first element in the table for the following program was 100, not 101 (which the formula produces.)
So I can write code like this obviously (In Ruby)
if level == 1 100 else (0.04 * (level **2) + 100).ceil end
Cute often isn't that great, though. So I'm wondering if other than factoring out the term by multiplying it by zero, if there's a better way to make it fit the formula that I'm just overlooking that one of you guys might see? Or is this just going to happen when a point doesn't fit on the function?
edit: This isn't a big deal, but I don't understand why my thread would be moved to the Ruby section (when it shouldn't have been) when this is the stuff that apparently should be posted in the general programming forum. So while it isn't a very big deal, I intentionally posted it because that's where it's supposed to be. There's a lot of people who aren't going to take a stab at this thread because it's in the Ruby section and the question isn't Ruby related at all.
You had it in the C/C++ section but said Ruby, so I figured it was just misplaced. The other thread wasn't in the wrong section, just a more general section although it should belong in C/C++.
Did you want it in the general code section? I'm still not sure why it was in the C/C++ section though?
You had it in the C/C++ section but said Ruby, so I figured it was just misplaced. The other thread wasn't in the wrong section, just a more general section although it should belong in C/C++.
Did you want it in the general code section? I'm still not sure why it was in the C/C++ section though?
I'm 99% sure it was in the coding & design forum. Either way, that's where it belongs, I think.
Not quite the same, except the formula is continuous.
(0.04 * ((level-1) **2) + 100).ceil
Right, that's kinda what I would liked to have done, but the table of values the formula produces doesn't match up with that except at level 1. For every other level the -1 throws it off.
roundup(0.04*(LV^2)+100)
which is fine in itself. The problem is there's often a special case for the first element that doesn't fit in the formula. For example the first element in the table for the following program was 100, not 101 (which the formula produces.)
So I can write code like this obviously (In Ruby)
For Zeno…
or I can get cute with some of these:
or
Cute often isn't that great, though. So I'm wondering if other than factoring out the term by multiplying it by zero, if there's a better way to make it fit the formula that I'm just overlooking that one of you guys might see? Or is this just going to happen when a point doesn't fit on the function?