2018d1 much faster (set vs. seq - TIL, again)

This commit is contained in:
Stefan Harmuth 2021-12-14 17:39:35 +01:00
parent 520791da78
commit b5569d4063

View File

@ -1,17 +1,18 @@
import std/intsets
import std/sequtils import std/sequtils
import tools/aoc import tools/aoc
let test: AOCDay = initAOCDay(1) let test: AOCDay = initAOCDay(1)
echo test.getInputInt().foldl(a + b) echo test.getInputInt().foldl(a + b)
var seen: seq[int] var seen: IntSet = initIntSet()
var freq: int = 0 var freq: int = 0
var found: bool = false var found: bool = false
while not found: while not found:
for x in test.getInputInt(): for x in test.getInputInt():
freq += x freq += x
if freq notin seen: if freq notin seen:
seen.add(freq) seen.incl(freq)
else: else:
echo freq echo freq
found = true found = true