Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Nice!
Btw, foldl1 (and foldr1) do the same as foldl but without a starting value.
So 1 + foldl1 (mod . (k +)) [2 .. n] is equivalent.
'If "This is not about coding skills", it should not be in "codewars".'
I disagree. Programming isn't only about coding skills. Making assertions about what the return of a function can look like is an important part of it.
This kata forces you to either do a lot of unnecessary work or make clever assertions and make your life easy.
But I agree that it shouldn't be 8 kyu.
Programming is a very wide field. Yes, you can do alot of programming without much math knowledge, but that is only because you are using a lot of libraries that do the math for you. Somebody has to write all these libraries and they need to know all this "useless math crap". So, please don't be ignorant and recognize the actual usefullness of these katas.
If you don't want to dive into this sort of programming just skip those katas.
Stop showing off pls (:
This comment is hidden because it contains spoiler information about the solution
I just want to add, that it is NOT necessary to find the primefactors of each factor in the factorial. That is just slow to do that and doesn't scale very well.
If we have [2..n] as the representation of the factorial and p a prime, we know that there are n/p (rounded down) numbers that singaly divide into p, n/p^2 numbers that doubaly divide into p and so on.
So we just add up: n/p + n/p^2 + n/p^3 + n/p^4 ... until p^k is bigger than n, since then every term will be equal to 0.
We do this for every p <= n and that's it.
I learned a lot about types in this kata, because I was forced to think about it more than I usually have to. Thanks, loooking forward to the next in this series.
sure thing. actually i found a couple of amazing solutions that i didn't think of. this website is awsome
You're welcome, recursion is a bit tricky until you get the hang of it. Now that you solved it without it, see other solutions that use recursion and analyze how they work.
you are right. i fixed my code using a while loop instead of recursion. it worked fine. thanks again for your time.
No problem, the answer to your problem was there too btw:
thanks
Already answered below.
Because you used a global var, and it keeps its value when your function is called more than once. Please, I know you said you read it, but read this again: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution it says there also how to post code with markdown formatting, etc. We wrote it so we don't need to repeat the same over and over.
I mean, there are different labels for posts here, it's documented in the github page, I'll copy and paste what it says about it:
Loading more items...