50 lines
1.1 KiB
Rust
50 lines
1.1 KiB
Rust
mod solution;
|
|
use solution::solution;
|
|
|
|
mod input_data;
|
|
use input_data::load_actual;
|
|
|
|
use reqwest::blocking::Client;
|
|
use reqwest::header::COOKIE;
|
|
|
|
use std::{time::Instant, env};
|
|
|
|
fn main() {
|
|
let year = 2024;
|
|
let day = 2;
|
|
|
|
let Ok(data) = load_actual(year, day)
|
|
else { panic!("No Input Data"); };
|
|
|
|
let now = Instant::now();
|
|
|
|
let part1 = solution(&data, year, day, 1).unwrap();
|
|
|
|
let elapsed1 = now.elapsed();
|
|
|
|
let now = Instant::now();
|
|
|
|
let part2 = solution(&data, year, day, 2).unwrap();
|
|
|
|
let elapsed2 = now.elapsed();
|
|
|
|
println!("Part 1 result is {}, took {}ms", part1, elapsed1.as_millis());
|
|
println!("Part 2 result is {}, took {}ms", part2, elapsed2.as_millis());
|
|
|
|
}
|
|
|
|
fn fetch_data(year, day) -> Result<(), Box<dyn std::error::Error>> {
|
|
let url = format!("https://adventofcode.com/{year}/day/{day}/input");
|
|
let session_cookie = env::var("ADVENT_TOKEN")?;
|
|
|
|
let client = Client::new();
|
|
let response = client
|
|
.get(url)
|
|
.header(COOKIE, session_cookie)
|
|
.send()?;
|
|
|
|
let body = response.text()?;
|
|
println!("Response: {}", body);
|
|
|
|
Ok(())
|
|
}
|