Skip to content

Commit 9293df6

Browse files
authored
Initial commit
0 parents  commit 9293df6

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
.idea
3+
Cargo.lock

Diff for: Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "adv-code-2024"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
anyhow = "1.0.93"
8+
code-timing-macros = { version = "0.0.5", features = ["release"] }
9+
const_format = "0.2.33"
10+
11+
# Additional recommended dependencies
12+
itertools = "0.13.0"
13+
regex = "1.11.1"

Diff for: README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Template for solving Advent of Code puzzles in Rust with RustRover
2+
3+
Read the [blog post](https://blog.jetbrains.com/rust/2024/11/29/advent-of-code-in-rust-for-the-rest-of-us/) that explains the structure and rationale behind this template.
4+
5+
## Usage
6+
7+
1. Create a new project from the template repository:
8+
- Using GitHub’s templating feature: Simply click the Use this template [button](https://github.com/new?template_name=advent-of-code-rust-template&template_owner=bravit) on the repository page, create a new repository, and then open it in [RustRover](https://www.jetbrains.com/rust/) by selecting *File | New | Project From Version Control…*.
9+
- Adding the template to RustRover: You can integrate the template directly into RustRover and use the regular New Project wizard.
10+
11+
2. Whenever you're ready to start solving a new day's puzzle:
12+
- Open the `bin` folder, copy and paste the `NN.rs` file into it, and give it the corresponding name (`01.rs`, `02.rs`, etc.).
13+
- In the `input` folder, create and fill the input data file (`01.txt`, `02.txt`, etc.).
14+
- Fill in the `DAY` constant in the freshly created file.
15+
- Run the current day's solution to check if it compiles (you can use the gutter icon next to the `main` function).
16+
- Fill in `<TEST-INPUT>`.
17+
- Write the expected answer for the test data in the `assert_eq` statement in *Part 1*.
18+
- Now you're ready to write your solution in the `part1` function (inside `main`).
19+
- Use `Shift+F10` (Win/Linux) or `Ctrl-R` (macOS) to re-run the same program.
20+
21+
3. When you're done with the first part of the puzzle, use folding to hide *Part 1*.
22+
23+
4. Uncomment *Part 2*, fill in the test data assertion, and start solving it.

Diff for: input/.keep

Whitespace-only changes.

Diff for: src/bin/NN.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use anyhow::*;
2+
use std::fs::File;
3+
use std::io::{BufRead, BufReader};
4+
use code_timing_macros::time_snippet;
5+
use const_format::concatcp;
6+
use adv_code_2024::*;
7+
8+
const DAY: &str = "NN"; // TODO: Fill the day
9+
const INPUT_FILE: &str = concatcp!("input/", DAY, ".txt");
10+
11+
const TEST: &str = "\
12+
<TEST-INPUT>
13+
"; // TODO: Add the test input
14+
15+
fn main() -> Result<()> {
16+
start_day(DAY);
17+
18+
//region Part 1
19+
println!("=== Part 1 ===");
20+
21+
fn part1<R: BufRead>(reader: R) -> Result<usize> {
22+
// TODO: Solve Part 1 of the puzzle
23+
let answer = reader.lines().flatten().count();
24+
Ok(answer)
25+
}
26+
27+
// TODO: Set the expected answer for the test input
28+
assert_eq!(0, part1(BufReader::new(TEST.as_bytes()))?);
29+
30+
let input_file = BufReader::new(File::open(INPUT_FILE)?);
31+
let result = time_snippet!(part1(input_file)?);
32+
println!("Result = {}", result);
33+
//endregion
34+
35+
//region Part 2
36+
// println!("\n=== Part 2 ===");
37+
//
38+
// fn part2<R: BufRead>(reader: R) -> Result<usize> {
39+
// Ok(0)
40+
// }
41+
//
42+
// assert_eq!(0, part2(BufReader::new(TEST.as_bytes()))?);
43+
//
44+
// let input_file = BufReader::new(File::open(INPUT_FILE)?);
45+
// let result = time_snippet!(part2(input_file)?);
46+
// println!("Result = {}", result);
47+
//endregion
48+
49+
Ok(())
50+
}

Diff for: src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn start_day(day: &str) {
2+
println!("Advent of Code 2024 - Day {:0>2}", day);
3+
}
4+
5+
// Additional common functions
6+
7+
#[cfg(test)]
8+
mod tests {
9+
use super::*;
10+
11+
#[test]
12+
fn it_works() {
13+
start_day("00");
14+
}
15+
}

0 commit comments

Comments
 (0)