DEV Community

Discussion on: Daily Challenge #13 - Twice Linear

Collapse
ganderzz profile image
Dylan Paulus • Edited on

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)