Nim
Time: ./main 0.04s user 0.01s system 39% cpu 0.113 total
./main 0.04s user 0.01s system 39% cpu 0.113 total
import sequtils, algorithm proc dblLinear(u: int): seq[int] = result.add(1) for i in 0..<u: let y = 2 * result[i] + 1 let z = 3 * result[i] + 1 result.add(y) result.add(z) result.sort() echo $dblLinear(100000)
Not familiar with nim. It looks like result is a list, and that duplicate values are being added to it. Is that not the case?
I think you're right! Was testing with too small of an input-set to see any duplicates. :)
Cheap fix (./main 341.16s user 0.52s system 99% cpu 5:42.40 total):
import sequtils, algorithm proc dblLinear(u: int): seq[int] = result.add(1) for i in 0..<u: let y = 2 * result[i] + 1 let z = 3 * result[i] + 1 if not (y in result): result.add(y) if not (z in result): result.add(z) result.sort() echo $dblLinear(100000)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nim
Time:
./main 0.04s user 0.01s system 39% cpu 0.113 total
Not familiar with nim. It looks like result is a list, and that duplicate values are being added to it. Is that not the case?
I think you're right! Was testing with too small of an input-set to see any duplicates. :)
Cheap fix (./main 341.16s user 0.52s system 99% cpu 5:42.40 total):