variable names are too long and the test only assert the result to be 58...
This is beautiful.
Huh... I didn't about the chr method. It gives you the first letter of a string. Cool
Would be good to know what that 64 is.
your solution is brilliant because is simple and clean. It's the solution that teacher shows in class.
Interesting solution using binomial series simplification. What is interesting here is that m = (n^2*(n+1)^2)/4 . When I try to simplify n in terms of m would be n*(n+1) = sqrt(m * 4). However, if you assume that n is very small compared to m and that performing n.to_i will remove the error, then you can simplify further to n^2 = sqrt(m * 4) and thus get n = (m * 4)^(1/4). This is where the check to plug n back into the binomial simplication will confirm that assumption. I'm amazed that it will work and pretty cool!
This will add a space before every capital letter regardless of whether it is part of a camelcased word...
Please, I need someone to explain this.... this is crazy. I first tried to avoid loops but couldn't think of any theorem to rely on.
Thank you for your answer. Such application of maths into CS.
I ended up looking through Bernoulli polynomials, Nicomachus's theorem, Faulhaber's formula and stuff, none of which I understand.
But I'll start reading more on Maths from now. And on algorithms.
If you can kindly point to some resources, that'd be so great.
But thanks again for your inspiring solution.
Does someone else consider this less readable and intuitive than, for example, cjvirtucio87's one?
It is very good that you found a solution without cycles, because this executes much faster. Simply stated, the author has found a formula guarantees some constant N actions while cycle gives us a different actions value which depends on 'm' (the more 'm' will increase, the more actions it will give us inside the cycle). I tried to make my script like the autor have made, but realized that I have not enough math knowledges :) Like your solution, thank you for it!
Nice. Didn't think of using ternary operators. Tried recursing but my node count kept getting reset in my solution.