Last active
December 1, 2021 14:31
-
-
Save ilmanzo/565b272c21b60310da8647dd4b1e2d29 to your computer and use it in GitHub Desktop.
Advent of Code 2021: day1 solution in Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/strutils | |
import std/sequtils | |
proc count_increases(items : seq[int]) : int = | |
for i in 1 .. items.high: | |
if items[i] > items[i - 1]: | |
inc result | |
proc get_sums(items: seq[int]) : seq[int] = | |
for i in countup(2,items.len-1): | |
result.add(items[i-2]+items[i-1]+items[i]) | |
let input: seq[int] = "../input.txt".lines.toSeq.map(parseInt) | |
echo "Part1: ",input.count_increases() | |
echo "Part2: ",input.get_sums().count_increases() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
first try in Nim