Ad
  • Default User Avatar

    Nice!
    Btw, foldl1 (and foldr1) do the same as foldl but without a starting value.
    So 1 + foldl1 (mod . (k +)) [2 .. n] is equivalent.

  • Default User Avatar

    '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.

  • Default User Avatar

    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.

  • Custom User Avatar

    Stop showing off pls (:

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    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.

  • Default User Avatar

    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.

  • Custom User Avatar

    sure thing. actually i found a couple of amazing solutions that i didn't think of. this website is awsome

  • Custom User Avatar

    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.

  • Custom User Avatar

    you are right. i fixed my code using a while loop instead of recursion. it worked fine. thanks again for your time.

  • Custom User Avatar

    No problem, the answer to your problem was there too btw:

    Check if your solution passes two successive calls with different inputs. It's sometimes the case that solution contains some global variables or static members and stale state is carried over from one invocation to another.

  • Custom User Avatar
  • Custom User Avatar

    Already answered below.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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:

    • Mark your post with Question label if you have some problems solving the kata and want to ask for help.
    • Mark your post with Suggestion label if you want to propose some changes or improvements to discussed kata. It's also customary when posting a translation to post a link as a suggestion as well, in case the notification gets lost.
    • Mark your post with Issue label only if you are perfectly sure that kata is in some way broken, and needs to be edited and fixed. If you have difficulties with solving the kata, raise a Question, and not an Issue.
  • Loading more items...