Skip to content

Commit a46140b

Browse files
committed
Simplify input path handling
1 parent d6c0d1a commit a46140b

File tree

9 files changed

+20
-34
lines changed

9 files changed

+20
-34
lines changed

src/day01.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::collections::HashMap;
22
use std::fs;
33
use std::iter::zip;
4-
use std::path::PathBuf;
54

6-
pub fn day01(mut input_path: PathBuf) {
7-
input_path.push("01.txt");
5+
pub fn day01(input_path: String) {
86
let input: String = fs::read_to_string(input_path).unwrap();
97
let (mut left, mut right) = parse_input(&input);
108

src/day02.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::collections::HashMap;
22
use std::fs;
33
use std::hash::Hash;
4-
use std::path::PathBuf;
54

6-
pub fn day02(mut input_path: PathBuf) {
7-
input_path.push("02.txt");
5+
pub fn day02(input_path: String) {
86
let content = fs::read_to_string(input_path).unwrap();
97
let input = parse_input(&content);
108

src/day03.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::fs;
2-
use std::path::PathBuf;
32

4-
pub fn day03(mut input_path: PathBuf) {
5-
input_path.push("03.txt");
3+
pub fn day03(input_path: String) {
64
let content = fs::read_to_string(input_path).unwrap();
75

86
println!(

src/day04.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::fs;
2-
use std::path::PathBuf;
32

4-
pub fn day04(mut input_path: PathBuf) {
5-
input_path.push("04.txt");
3+
pub fn day04(input_path: String) {
64
let input = fs::read_to_string(input_path).unwrap();
75

86
let data = parse_input(&input);

src/day05.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::collections::{HashMap, HashSet};
22
use std::fs;
3-
use std::path::PathBuf;
43

54
use itertools::Itertools;
65

7-
pub fn day05(mut input_path: PathBuf) {
8-
input_path.push("05.txt");
6+
pub fn day05(input_path: String) {
97
let input = fs::read_to_string(input_path).unwrap();
108

119
let (rules, pages_list) = parse_input(&input);

src/day06.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ use std::collections::BTreeMap;
1111
use std::collections::HashMap;
1212
use std::collections::HashSet;
1313
use std::fs;
14-
use std::path::PathBuf;
1514
use tailcall::tailcall;
1615

17-
pub fn day06(mut input_path: PathBuf) {
18-
input_path.push("06.txt");
16+
pub fn day06(input_path: String) {
1917
let content = fs::read_to_string(input_path).unwrap();
2018

2119
let (field, guard) = read(&content);

src/day07.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::{fs, iter::zip, num::ParseIntError, path::PathBuf, str::FromStr};
1+
use std::{fs, iter::zip, num::ParseIntError, str::FromStr};
22

33
use itertools::Itertools;
44
use rayon::prelude::*;
55

6-
pub fn day07(mut input_path: PathBuf) {
7-
input_path.push("07.txt");
6+
pub fn day07(input_path: String) {
87
let content = fs::read_to_string(input_path).unwrap();
98

109
let equations: Vec<Equation> = content.lines().map(|l| l.parse().unwrap()).collect();

src/day08.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ use std::{
22
cmp,
33
collections::{HashMap, HashSet},
44
fs,
5-
path::PathBuf,
65
};
76

87
use itertools::iproduct;
98

10-
pub fn day08(mut input_path: PathBuf) {
11-
input_path.push("08.txt");
9+
pub fn day08(input_path: String) {
1210
let content = fs::read_to_string(input_path).unwrap();
1311

1412
let (antennas, corner) = read(&content);

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(cmp_minmax)]
22

33
use clap::Parser;
4-
use std::path::PathBuf;
54

65
mod day01;
76
mod day02;
@@ -16,19 +15,21 @@ mod day08;
1615
struct Args {
1716
#[arg(short, long, default_value_t = 0)]
1817
day: u8,
18+
19+
#[arg(short, long, default_value = "input")]
20+
input_path: String,
1921
}
2022

2123
fn main() {
2224
let args = Args::parse();
23-
let input = PathBuf::from("input");
2425
match args.day {
25-
1 => day01::day01(input),
26-
2 => day02::day02(input),
27-
3 => day03::day03(input),
28-
4 => day04::day04(input),
29-
5 => day05::day05(input),
30-
6 => day06::day06(input),
31-
7 => day07::day07(input),
32-
_ => day08::day08(input),
26+
1 => day01::day01(args.input_path),
27+
2 => day02::day02(args.input_path),
28+
3 => day03::day03(args.input_path),
29+
4 => day04::day04(args.input_path),
30+
5 => day05::day05(args.input_path),
31+
6 => day06::day06(args.input_path),
32+
7 => day07::day07(args.input_path),
33+
_ => day08::day08(args.input_path),
3334
}
3435
}

0 commit comments

Comments
 (0)