wiwi/
aoc.rs

1use crate::prelude::*;
2use crate::chain::WithSelf as _;
3use std::io::Read;
4
5#[inline]
6pub fn get_input(year: usize, day: usize) -> String {
7	String::from_utf8(get_input_buf(year, day)).unwrap()
8}
9
10#[inline]
11pub fn get_input_buf(year: usize, day: usize) -> Vec<u8> {
12	let path = env::current_dir()
13		.expect("failed to get current dir")
14		.with_self(|p| p.push("input"))
15		.with_self(|p| p.push(&*format!("{year:04}-{day:02}")));
16
17	let file = fs::OpenOptions::new()
18		.read(true)
19		.open(&*path)
20		.unwrap_or_else(|e| panic!("failed to read input file (tried `{path:?}`): {e}"));
21
22	(file, Vec::new())
23		.with_self(|(f, v)| {
24			f.read_to_end(v)
25				.unwrap_or_else(|e| panic!("error occured reading input file at `{path:?}`: {e}"));
26		})
27		.1
28}
29
30#[inline]
31pub fn print_p1<T>(result: T)
32where
33	T: fmt::Display
34{
35	println!("part1: {result}")
36}
37
38#[inline]
39pub fn print_p2<T>(result: T)
40where
41	T: fmt::Display
42{
43	println!("part2: {result}")
44}
45
46pub mod prelude {
47	pub use crate::prelude::*;
48	pub use crate::aoc::{ self, * };
49	pub use crate::chain::{ self, * };
50	pub use crate::num::*;
51}