Challenge
Your challenge is to construct a building which will be made of a pile of n cubes. The cube at the bottom will have a volume of n^3, the ...
For further actions, you may consider blocking this person and/or reporting abuse
I made this one harder than it had to be at first :) I was trying to solve the math problem, but when I switched to just using a loop, it went super quick.
Below is what I came up with in JS, and I recorded my process, so you can watch me solve it! youtu.be/NVA_YuRqscE
Nice solution, and nice video explaining it. May I ask, how did you record it?
Thanks!
I have a mac and use screenflow for recording: telestream.net/screenflow/overview...
If you use Windows, then camtasia is very similar: techsmith.com/video-editor.html
I believe QuickTime is a free option for screen recording, but then you still need to do editing somehow.
I make a lot of screencasts, so my mic setup is pretty good (read: expensive :) ) - but you don't need a fancy mic to get started! A lot of headphones (like the base Apple headphones) have pretty good mics in them actually, and then, you can use the audio tools in screenflow to clean it up, or use a service like auphonic.com/ to get some really high quality sound.
Hope that helps!
(I should probably write that up into a blog post so I can just point people to it 😀)
Thanks for the answer. I will give screenflow a try, and maybe get a new headset with microphone.
Btw, that's a blog post I would definitely read/watch. Let me know if you end up posting it.
Will do!
Ok, now I got a solution thanks to Wolfram Alpha:
I did the naive iterative solution first, and then I saw the formula from Dominik G, and wanted to compare the two solutions.
Here are the two functions in Rust.
Iterative:
Formula:
And a little benchmark (with the number
91716553919377
from the examples):Formula is ~290 times faster than the iterative method (for me; your numbers may vary!)
A bit of related info: I published my solutions to daily challenges (in Rust) on GitHub - currently days 43-55, but I plan to expand on that :)
Recursive, functional approach using lazy streams in Scala:
It feels like there should be some mathematical formula/pattern that would allow to figure things out without having to loop over all the possible results.
I just found that 13 + 23 +...+ n3 = (1/4)n2 * (n+1)2
So you would need to reverse that.
m=((1/4)n*(n+1))2
sqrt(m)=(1/4)n*(n+1) //given positive n and m
4*sqrt(m)=n*(n+1)
That's as far as I get in my head
n = 1/2 (sqrt(1 - 8 sqrt(m)) - 1)
Wolfram alpha to the rescue
So my solution would be:
That's amazing
But it doesn't work. :( Just tested it after posting.
Here is a loop based solution, I'm sure there is a formula for finding it but I don't have time right now to figure it out or Go find it.
cubes.go
cubes_test.go
Hoy,
With a reccursive aproach using Emacs Lisp
You might have to increase your max-lisp-eval-depth for great values.