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 465B

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