Ad
  • Default User Avatar

    Well four years later and there are still people (like me) running into this problem. There's even a test case testing for n=250k...

    But I think that's a good thing, as I've learned something from that.

    I had to look up other people's solutions. As it turns out the only difference to my solution was a cast to double. Without the cast I had a ratio [1] resulting from the division of two integers. And it seems like summing up a bunch of ratios is very inefficient.

    [1] https://clojure.org/reference/data_structures#_ratio

  • Custom User Avatar

    Yeah, there's a test case that asks it to be calculated on n = 25000, which takes a looooong time. I've tried optimizing it several ways and it still always times out

  • Custom User Avatar

    I'm having the same issue. I don't know what the value of n is for the test which times out, but on my machine I can go up to ~3500:

    user=> (time (series-sum 3500))
    "Elapsed time: 9775.32137 msecs"
    "3.76"
    

    I believe the code is right, as it solves a case which the author has provided an answer in a comment here:

    user=> (time (series-sum 59))
    "Elapsed time: 0.998973 msecs"
    "2.40"
    
  • Custom User Avatar
  • Custom User Avatar

    Sorry I cannot help you with it, I don't know Clojure. But I'll try to notify the translator about this.

  • Custom User Avatar

    Lang: Clojure

    All the tests passed, but when I'm trying to submit a solution, process terminates, because it took more than 10000ms to complete task. Well, I've tried several versions of solution, in case of making the programm more lightweight, but result is the same. What's the problem?