03-14-2007, 02:55 PM
So, I'm doing something for work where I need to do some Math/logic. It seems like a question I'd get on a CS exam. If you feel like having a crack at it, dooooo it!
So, I've got a result set and it won't all fit on one page. So, for example, I've got 12 results and I can fit 5 / page. I know only two things: the number of results and the max per page. How can I figure out how many are on a certain page given only the page number?
When you post a solution, use clear variable names like "cur_page" and "num_results", etc... You are allowed to use programming functions like ceil() and floor(). Do it as efficiently as possible. (A friend and I have figured it out 2 ways to get it on one line. Neither are particularly pretty. One uses a ternary operator, other looks like complex math equation. There has GOT to be a good way to do it. i.e. no ternary operator and in one statement.)
So, I've got a result set and it won't all fit on one page. So, for example, I've got 12 results and I can fit 5 / page. I know only two things: the number of results and the max per page. How can I figure out how many are on a certain page given only the page number?
When you post a solution, use clear variable names like "cur_page" and "num_results", etc... You are allowed to use programming functions like ceil() and floor(). Do it as efficiently as possible. (A friend and I have figured it out 2 ways to get it on one line. Neither are particularly pretty. One uses a ternary operator, other looks like complex math equation. There has GOT to be a good way to do it. i.e. no ternary operator and in one statement.)
My Tumblr
2008 Felt F75 - Pedal Power
2008 Felt F75 - Pedal Power

