My solutions to 2018's advent of code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

day01.nim 450B

1234567891011121314151617181920
  1. import intsets, math, sequtils, strutils
  2. let input = readFile("data/01.txt").splitLines.map(parseInt)
  3. proc part1(freqs: seq[int]): int =
  4. freqs.sum
  5. proc part2(freqs: seq[int]): int =
  6. var seen = initIntSet()
  7. var talley: int
  8. while true:
  9. for n in freqs:
  10. talley += n
  11. if talley in seen:
  12. return talley
  13. seen.incl(talley)
  14. echo part1(input)
  15. echo part2(input)