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.

day05.nim 588B

12345678910111213141516171819
  1. import sequtils, strutils
  2. func react(polymer: seq[char], skip: char): seq[char] =
  3. var count = 0
  4. for c in polymer:
  5. if c == skip or (ord(c) xor ord(skip)) == 32:
  6. continue
  7. if count > 0:
  8. if (ord(c) xor ord(result[count - 1])) == 32:
  9. result.delete(count - 1)
  10. count.dec
  11. continue
  12. result.add(c)
  13. count.inc
  14. let polymer = toSeq(readFile("data/05.txt").strip.items).react(' ')
  15. echo polymer.len
  16. echo min(toSeq('A'..'Z').map(proc(c: char): int = len(polymer.react(c))))