[ubuntu-mono] [Bug 572607] Re: Incorrect answer in the 'cube' task

Gregory Bonik gregory at bonik.org
Fri Apr 30 23:53:49 BST 2010


@Kamus, what?

If rows = columns = deepth = 4, then ans becomes 4*4*4 = 64. But that's
not the correct answer, neither is 96. The correct answer is 99.

'Deepth'" (should be 'depth' of course) is not the number of faces. It's
the number of cubes in the third dimension.

The correct code should be

n = random.Next(max_random)
ans = 0
for i in xrange(2, n + 1):
  ans += i**3

Alternatively, one can use the closed-form formula to compute the sum:
n = random.Next(max_random)
ans = (n*(n + 1) / 2)**2 - 1

It should be noted that in the case of unequal dimensions (i. e. rows,
cols and depth differ from each other) the task gets a bit harder.

-- 
Incorrect answer in the 'cube' task
https://bugs.launchpad.net/bugs/572607
You received this bug notification because you are a member of Ubuntu
CLI/Mono Uploaders, which is subscribed to gbrainy in ubuntu.

Status in GBrainy: New
Status in “gbrainy” package in Ubuntu: In Progress

Bug description:
Binary package hint: gbrainy

The 'correct' answer in the 'Cube' problem is indeed wrong. The task reads:

"How many cubes do you count in the figure below? (not counting the figure)",

and the picture of a big cube subdivided into n^3 small cubes follows (see attachment). The number n is either 4, 5, or 6. GBrainy says that for each n the correct answer is n^3 (i. e. 64 for n = 4, 125 for n = 5 and 216 for n = 6), but obviously that's wrong.

There are also sub-cubes of sizes 2x2x2, 3x3x3 and so on. For example, in the case of n = 4, one can find 99 cubes:

8 = 2^3 cubes of size 3x3x3,
27 = 3^3 cubes of size 2x2x2
and 64 = 4^3 cubes of size 1x1x1.

So, for an arbitrary n the correct answer is 1^3 + 2^3 + ... + n^3. In particular, the answer for n = 5 is 224, the answer for n = 6 is 440, and, as already mentioned, the answer for n =4 is 99.





More information about the Ubuntu-mono mailing list