Skip to content

Instantly share code, notes, and snippets.

@ilmanzo
Last active December 1, 2021 14:31
Show Gist options
  • Save ilmanzo/565b272c21b60310da8647dd4b1e2d29 to your computer and use it in GitHub Desktop.
Save ilmanzo/565b272c21b60310da8647dd4b1e2d29 to your computer and use it in GitHub Desktop.
Advent of Code 2021: day1 solution in Nim
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()
@ilmanzo
Copy link
Author

ilmanzo commented Dec 1, 2021

first try in Nim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment