DEV Community

Discussion on: Daily Challenge #55 - Building a Pile of Cubes

Collapse
 
dominikfg profile image
Dominik G • Edited

n = 1/2 (sqrt(1 - 8 sqrt(m)) - 1)

Wolfram alpha to the rescue

Thread Thread
 
dominikfg profile image
Dominik G

So my solution would be:

const cubes = m => {
  let n = (Math.sqrt(1 - 8 * Math.sqrt(m)) - 1)/2;

  return n === Math.floor(n) ? n : 0;
}
Thread Thread
 
alvaromontoro profile image
Alvaro Montoro

That's amazing

Thread Thread
 
dominikfg profile image
Dominik G

But it doesn't work. :( Just tested it after posting.