advent-of-code

advent of code (partial solutions)
Log | Files | Refs | README

commit a8e04591448fe9622d59224e1b88e395520905dd
parent 46796e60bae392767f19cf16fb534bf6be8a3b95
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue, 30 Nov 2021 21:13:00 -0800

day 1 crappy rust

Diffstat:
A2021/aoc01.rs | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/2021/aoc01.rs b/2021/aoc01.rs @@ -0,0 +1,31 @@ +use std::error::Error; +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut total = -1; + let mut last = 0; + let mut numbers = vec![]; + for line in stdin.lock().lines() { + let this = line?.parse()?; + if this > last { + total += 1; + } + last = this; + numbers.push(this); + } + let mut threetotal = -1; + let mut threelast = 0; + for i in 0..numbers.len() - 2 { + let three = numbers[i] + numbers[i + 1] + numbers[i + 2]; + if three > threelast { + threetotal += 1; + } + threelast = three; + } + println!("part 1: {}", total); + println!("part 2: {}", threetotal); + Ok(()) +}