From a7ba598a54a8883c83cb9ef2b04d653eecd92e28 Mon Sep 17 00:00:00 2001 From: j-james Date: Sun, 11 Dec 2022 18:15:44 -0800 Subject: Reorganize 2019 solutions --- 2019/four.nim | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 2019/four.nim (limited to '2019/four.nim') diff --git a/2019/four.nim b/2019/four.nim deleted file mode 100644 index eb6d933..0000000 --- a/2019/four.nim +++ /dev/null @@ -1,37 +0,0 @@ -# Day Four: Secure Container -import os, strutils, sequtils - -let input: string = paramStr(1) -let bounds: seq[int] = map(split(strip(readFile(input)), '-'), parseInt) -var valid, details: int = 0 - -proc criteria(password: int): bool = - var password: string = $password - for digit in 0 .. 4: - if password[digit] > password[digit+1]: - return false - for digit in 0 .. 4: - if password[digit] == password[digit+1]: - return true - return false - -proc extracriteria(password: int): bool = - var password: string = $password - for digit in 0 .. 4: - if password[digit] > password[digit+1]: - return false - for digit in 0 .. 4: - if password[digit] == password[digit+1]: - if digit == 0 or password[digit] != password[digit-1]: - if digit == 4 or password[digit] != password[digit+2]: - return true - return false - -for password in bounds[0] .. bounds[1]: - if criteria(password): inc(valid) - -for password in bounds[0] .. bounds[1]: - if extracriteria(password): inc(details) - -echo valid -echo details -- cgit v1.2.3-70-g09d2