09 Feb, 2011, Runter wrote in the 1st comment:
Votes: 0
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


For Zeno…
if(level == 1) 
return 100;
else
return ceil(0.04 * (level * level) + 100);


or I can get cute with some of these:

(100 if level == 1) or (0.04 * (level **2) + 100).ceil


((level == 1? 0 : 1) * 0.04 * (level **2) + 100).ceil


or
([level-1, 1].min * 0.04 * (level **2) + 100).ceil





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?
09 Feb, 2011, Zeno wrote in the 2nd comment:
Votes: 0
(Moved to Ruby section)
09 Feb, 2011, Runter wrote in the 3rd comment:
Votes: 0
Zeno said:
(Moved to Ruby section)


It wasn't a Ruby question.


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.
09 Feb, 2011, Zeno wrote in the 4th comment:
Votes: 0
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?
09 Feb, 2011, Runter wrote in the 5th comment:
Votes: 0
Zeno said:
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.
09 Feb, 2011, Zeno wrote in the 6th comment:
Votes: 0
Moved. Yeah, if it was originally in coding & design I would have left it. :)

Note by kiasyn:
Moderator logs show:
Feb 10, 2011, 6:49 am Zeno Moved a topic Moved topic #3288 from forum #44 to forum #43

This confirms it was originally in the C++ forum :)
10 Feb, 2011, Runter wrote in the 7th comment:
Votes: 0
Zeno said:
Moved. Yeah, if it was originally in coding & design I would have left it. :)

Note by kiasyn:
Moderator logs show:
Feb 10, 2011, 6:49 am Zeno Moved a topic Moved topic #3288 from forum #44 to forum #43

This confirms it was originally in the C++ forum :)


Well, my apologies, but had you moved it to the correct forum there'd be no confusion about where it was moved from. That was kinda the larger point.
11 Feb, 2011, Tyche wrote in the 8th comment:
Votes: 0
Not quite the same, except the formula is continuous.

(0.04 * ((level-1) **2) + 100).ceil
11 Feb, 2011, Runter wrote in the 9th comment:
Votes: 0
Tyche said:
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.
11 Feb, 2011, Newt wrote in the 10th comment:
Votes: 0
(0.04 * (level **2) + 100).ceil - (level==1)
11 Feb, 2011, Runter wrote in the 11th comment:
Votes: 0
Newt said:
(0.04 * (level **2) + 100).ceil - (level==1)


That's kinda clever but I think in the language I'm using level==1 evaluates to something other than 0 or 1 :p
11 Feb, 2011, Newt wrote in the 12th comment:
Votes: 0
Hmm…is there no way to set the first one as the exception and then the rest with (0.04 * ((level+1) **2) + 100).ceil or something similar?
11 Feb, 2011, Runter wrote in the 13th comment:
Votes: 0
Newt said:
Hmm…is there no way to set the first one as the exception and then the rest with (0.04 * ((level+1) **2) + 100).ceil or something similar?


well, yeah. I was just hoping for something in a unified formula. :p
12 Feb, 2011, Newt wrote in the 14th comment:
Votes: 0
(0.04 * (level **2) * ((1-level).abs / level)).ceil + 100).ceil …or ((0.04 * (level **2) * ((1-level).abs / level)).ceil).ceil + 100
12 Feb, 2011, Runter wrote in the 15th comment:
Votes: 0
Thanks Newt!
12 Feb, 2011, Newt wrote in the 16th comment:
Votes: 0
I think maybe we can do away with the abs even…(0.04 * (level **2) * ((level-1) / level).ceil).ceil + 100
0.0/16