[Tutor] Finding a nearest perfect cube

Danny Yoo dyoo at hashcollision.org
Fri Nov 8 03:07:00 CET 2013


>
>
> If i input a number, i should get a perfect cube nearest to it.
> For eg: if
> input=4, output=8
> input=8, output=27
> and so on....
>


Let's consider those examples.  Pretend you were given:

    input = 4

and the description of the problem.  Forget computers for a brief moment.
What would YOU do do solve this problem?  Why should I believe that "8" is
an acceptable answer to this?

This is one of the first steps to understanding the problem, to understand
the sample inputs and outputs.  If you find that those outputs make no
sense, then you've got to stop right now: no amount of coding will help if
you don't understand what you're trying to code.

Same question to 'input = 8'.  Why would "27" be an acceptable answer?  In
fact, I would argue that the expected answer here is wrong if we pay
attention to the problem statement.  8 is a perfect cube, and 8 is closest
to 8, as math.abs(8 - 8) == 0!

So you must define what you mean by "closest".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131107/35872b98/attachment.html>


More information about the Tutor mailing list