Skip to content

Commit

Permalink
minor improvement
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Läufer <[email protected]>
  • Loading branch information
klaeufer committed Mar 22, 2024
1 parent ac0acde commit 5548ae1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/bin/day1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() -> io::Result<()> {

fn run_calibration(label: &str, file_name: &str, digits: &[String]) -> io::Result<()> {
let file = File::open("data/".to_string() + file_name)?;
let lines = BufReader::new(file).lines().map(Result::unwrap).collect::<Vec<_>>();
let lines = BufReader::new(file).lines().collect::<io::Result<Vec<String>>>()?;
println!("Day 1 {} solution: {}", label, calibrate_lines(&lines, digits));
Ok(())
}
Expand Down Expand Up @@ -48,7 +48,7 @@ fn calibrate_line(line: &str, digits: &[String]) -> Option<usize> {
}

static SIMPLE_DIGITS: Lazy<Vec<String>> = Lazy::new(|| {
(0 .. 10).map(|d| d.to_string()).collect::<Vec<_>>()
(0 .. 10).map(|d| d.to_string()).collect()
});

static WORD_DIGITS: Lazy<Vec<String>> = Lazy::new(|| {
Expand Down
5 changes: 2 additions & 3 deletions src/bin/day5.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::{
fs::File,
io::{BufRead, BufReader},
io::{self, BufRead, BufReader},
};

use log::info;
use anyhow::Result; // simplified error handling
use once_cell::sync::Lazy; // global constants
use regex::Regex;

static NUMBER: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d+)").unwrap());

fn main() -> Result<()> {
fn main() -> io::Result<()> {
env_logger::init();
let file = File::open("data/day5input.txt")?;
let mut lines = BufReader::new(file)
Expand Down

0 comments on commit 5548ae1

Please sign in to comment.