Lets use include_str! this year
This commit is contained in:
parent
7c4b0ead30
commit
54b6ccfc26
@ -1,20 +1,16 @@
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::io::BufReader;
|
||||
use std::time::Instant;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
const INPUT: &str = "input/input.txt";
|
||||
const INPUT: &str = include_str!("input/input.txt");
|
||||
|
||||
fn solve_part1(input_path: &str) -> Result<i32> {
|
||||
let file = File::open(input_path)?;
|
||||
let reader = BufReader::new(file);
|
||||
fn solve_part1(input: &str) -> Result<i32> {
|
||||
let lines = input.trim().lines();
|
||||
|
||||
let mut increases = 0;
|
||||
let mut prev_reading: Option<i32> = None;
|
||||
for line in reader.lines() {
|
||||
let reading = line?.parse()?;
|
||||
for line in lines {
|
||||
let reading = line.parse()?;
|
||||
if let Some(prev) = prev_reading {
|
||||
if reading > prev {
|
||||
increases += 1;
|
||||
@ -26,17 +22,13 @@ fn solve_part1(input_path: &str) -> Result<i32> {
|
||||
Ok(increases)
|
||||
}
|
||||
|
||||
fn solve_part2(input_path: &str) -> Result<i32> {
|
||||
let file = File::open(input_path)?;
|
||||
let reader = BufReader::new(file);
|
||||
fn solve_part2(input: &str) -> Result<i32> {
|
||||
let lines: Vec<&str> = input.trim().lines().collect();
|
||||
|
||||
let mut increases = 0;
|
||||
let mut prev_sum: Option<i32> = None;
|
||||
let all_lines = reader
|
||||
.lines()
|
||||
.collect::<Result<Vec<String>, std::io::Error>>()?;
|
||||
for lines in all_lines.windows(3) {
|
||||
let sum = lines.iter().map(|s| s.parse::<i32>().unwrap()).sum();
|
||||
for group in lines.windows(3) {
|
||||
let sum = group.iter().map(|s| s.parse::<i32>().unwrap()).sum();
|
||||
if let Some(prev) = prev_sum {
|
||||
if sum > prev {
|
||||
increases += 1;
|
||||
@ -62,7 +54,7 @@ fn main() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const TEST_INPUT: &str = "input/test.txt";
|
||||
const TEST_INPUT: &str = include_str!("input/test.txt");
|
||||
|
||||
#[test]
|
||||
fn solves_part1() {
|
||||
|
Loading…
Reference in New Issue
Block a user