2

We ran into a question on a computer science test that basically asked what is $\pi^3$ rounded up to the nearest whole number. The value of $\pi$ as defined by the programming language was $3.141592653589793$ and afterwards, we found out we would've needed to go to $3.1415$ to get the right answer. The difficult part is that the test allows no calculator, and you get on average one minute per question. Maybe there's some easy trick to solve this?

EDIT: Exact question:

What is the output by the code to the right?

System.out.println(Math.ceil(Math.pow(Math.PI, (int) Math.round(Math.max(3.45, 3.3)))));

(The language is Java)

Badr B
  • 631
  • 5
  • 13
  • 3
    I'm concerned about the word "basically"... do you happen to have the exact text of the question? – The Count Mar 01 '18 at 00:49
  • With a calculator $\pi^3 = 31.006...$ so clearly not a reasonable exam question. I concur with @TheCount - we need the exact wording. – Ethan Bolker Mar 01 '18 at 00:52
  • +The Count Sure I'll edit the post. Keep in mind though these tests are known for their impractical code haha. – Badr B Mar 01 '18 at 00:54
  • 1
    Now that you have the edit: I am strictly not at all a computer scientist, but you may get more slick answers over on the CS site. – The Count Mar 01 '18 at 00:59
  • +The Count Thanks for the feedback, I'll give that a shot. – Badr B Mar 01 '18 at 01:02
  • Ah, so it does not ask the nearest integer. It actually asks the other one. –  Mar 01 '18 at 01:07
  • +G. Sassatelli Yeah which is why the question is pretty absurd, because $\pi^3$ is about $31.006$ and you're supposed to round that up. – Badr B Mar 01 '18 at 01:14
  • 1
    @TheCount There are some slick math answers under Proving $\pi^3 \gt 31$. – dxiv Mar 01 '18 at 01:15
  • 2
    I hate it. If you ceiling up $\pi$ you get $32$ but it's so close to $31$ that any approximations $3\frac 18$ or $\sqrt 10$ or $3\frac 17$ won't give you a very good idea whether it goes over $31$ or not. – fleablood Mar 01 '18 at 01:24
  • @fleablood Yeah that's the most annoying part of it haha – Badr B Mar 01 '18 at 01:27

1 Answers1

3

Remember that $\sqrt{10}=3.1622$ is close to $\pi =3.1415$.

Therefor $\pi ^3 $ is approximated by $10\pi =31.4159$ which is closest to the integer $31$.

The ceiling of $\pi ^3 $ is then $32.$

  • I suppose this depends on knowing $\sqrt{10}$ to four decimals as common knowledge, but I do like it. – The Count Mar 01 '18 at 00:58
  • 3
    Don't need to know $\sqrt {10}$ at all. If $\pi\approx \sqrt{10}$ then $\pi^2 \approx 10$ and $\pi^3 \approx 10\pi$. What I don't like about this is that we are expected to trust that $\pi \approx \sqrt 10$ is within acceptable margin of error? And that $3.1$ and $3.2$ are not? – fleablood Mar 01 '18 at 01:01
  • Wow that's pretty amazing. Still absurd they expect us to just know that haha. But this is the best explanation I've received so far. Thanks! – Badr B Mar 01 '18 at 01:01
  • Similarly they expect us to know that $log(\pi ) =.497$ is approximated by $0.5$ – Mohammad Riazi-Kermani Mar 01 '18 at 01:06
  • I knew $\sqrt{\pi} \approx 10$ but not whether it was close enough. See http://www.math.harvard.edu/~elkies/Misc/pi10.pdf – Ethan Bolker Mar 01 '18 at 01:06
  • 1
    It is the other way around $ \sqrt{10} \approx \pi $ – Mohammad Riazi-Kermani Mar 01 '18 at 01:08
  • @MohammadRiazi-Kermani Of course. – Ethan Bolker Mar 01 '18 at 01:17
  • Another strategy that isn't quite good enough. CS folks know $32^2 = 2^{10} = 1024 \approx 1000$, so $\pi^3 \approx 10 \pi$. But how close? – Ethan Bolker Mar 01 '18 at 01:19
  • 2
    31.4159 which is closest to the integer 31 But rounds up to $32$, which is what the question was asking for. The result is still correct, but the justification is not obvious. – dxiv Mar 01 '18 at 01:36
  • 3
    @EthanBolker May be interesting to note that the roughest rational approximation gives the much better estimate $,(22/7)^3 = 31.04\ldots,$, which hints at the correct answer of $,32,$, but is still not enough to prove it. – dxiv Mar 01 '18 at 01:38