Skip to content

Commit 6068fdd

Browse files
committed
readme
1 parent b6f89be commit 6068fdd

File tree

6 files changed

+169
-4
lines changed

6 files changed

+169
-4
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ regex = "1.11.1"
1414
name = "generate"
1515
path = "bin/generate/main.rs"
1616

17+
[[bin]]
18+
name = "readme"
19+
path = "bin/readme/main.rs"
20+
1721
# # uncomment to enable release profile for faster tests
1822
[profile.test]
1923
inherits = "release"

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
# Advent of Code 2024 🦀🎄
22

33
![DALL·E 2024-12-03 06 34 26 - A whimsical Christmas scene featuring a traditional green Christmas tree adorned with ornaments and fairy lights, with numerous colorful crabs, both s](https://github.com/user-attachments/assets/14635fa6-d3ca-4193-af7f-ee1aea1a7fb2)
4+
5+
<!---Results Table BEGIN-->
6+
## Status
7+
| Day | Part 1 | Part 2 |
8+
|-----|--------|--------|
9+
| 1 | ⭐️ | ⭐️ |
10+
| 2 | ⭐️ | ⭐️ |
11+
| 3 | ⭐️ | ⭐️ |
12+
| 4 | ⭐️ | ⭐️ |
13+
| 5 | ⭐️ | ⭐️ |
14+
| 6 | ⭐️ | ⭐️ |
15+
| 7 | ⭐️ | ⭐️ |
16+
| 8 | ⭐️ | ⭐️ |
17+
| 9 | ⭐️ | ⭐️ |
18+
| 10 | ⭐️ | ⭐️ |
19+
| 11 | ⭐️ | ⭐️ |
20+
| 12 | ⭐️ | ⭐️ |
21+
| 13 | ⭐️ | ⭐️ |
22+
| 14 | ⭐️ | ⭐️ |
23+
| 15 | ⭐️ | ⭐️ |
24+
| 16 | | |
25+
| 17 | | |
26+
| 18 | | |
27+
| 19 | ⭐️ | ⭐️ |
28+
| 20 | | |
29+
| 21 | | |
30+
| 22 | | |
31+
| 23 | | |
32+
| 24 | | |
33+
| 25 | | |
34+
<!---Results Table END-->

bin/readme/main.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use core::panic;
2+
use std::process::Command;
3+
4+
#[derive(Debug)]
5+
enum TestStatus {
6+
Missing,
7+
Passed,
8+
Failed,
9+
}
10+
11+
#[derive(Debug)]
12+
struct DayTest {
13+
part1: TestStatus,
14+
part2: TestStatus,
15+
}
16+
17+
fn get_days() -> Vec<DayTest> {
18+
let mut days = Vec::new();
19+
for _ in 1..=25 {
20+
days.push(DayTest {
21+
part1: TestStatus::Missing,
22+
part2: TestStatus::Missing,
23+
});
24+
}
25+
26+
let output = Command::new("cargo")
27+
.arg("test")
28+
.arg("--no-run")
29+
.output()
30+
.expect("Failed to execute command");
31+
32+
if output.status.success() {
33+
println!("Tests compiled successfully.");
34+
} else {
35+
panic!("Tests failed to compile.");
36+
}
37+
38+
let run_output = Command::new("cargo")
39+
.arg("test")
40+
.output()
41+
.expect("Failed to execute tests");
42+
43+
let re =
44+
regex::Regex::new(r"^test day(?<day>\d+)::tests::test_part(?<part>\d) ... (?<status>\w+)$")
45+
.unwrap();
46+
47+
for line in String::from_utf8_lossy(&run_output.stdout).lines() {
48+
let captures = match re.captures(line) {
49+
Some(captures) => captures,
50+
None => continue,
51+
};
52+
let day = captures
53+
.name("day")
54+
.unwrap()
55+
.as_str()
56+
.parse::<usize>()
57+
.unwrap();
58+
let part = captures
59+
.name("part")
60+
.unwrap()
61+
.as_str()
62+
.parse::<usize>()
63+
.unwrap();
64+
let status = captures.name("status").unwrap().as_str();
65+
66+
let day = &mut days[day - 1];
67+
match part {
68+
1 => {
69+
day.part1 = match status {
70+
"ok" => TestStatus::Passed,
71+
_ => TestStatus::Failed,
72+
}
73+
}
74+
2 => {
75+
day.part2 = match status {
76+
"ok" => TestStatus::Passed,
77+
_ => TestStatus::Failed,
78+
}
79+
}
80+
_ => panic!("Invalid part number"),
81+
}
82+
}
83+
84+
days
85+
}
86+
87+
fn build_markdown_table(days: Vec<DayTest>) -> String {
88+
let mut table = String::new();
89+
table.push_str("| Day | Part 1 | Part 2 |\n");
90+
table.push_str("|-----|--------|--------|\n");
91+
92+
for (i, day) in days.iter().enumerate() {
93+
table.push_str(&format!(
94+
"| {:>3} | {:>6} | {:>6} |\n",
95+
i + 1,
96+
match day.part1 {
97+
TestStatus::Missing => "",
98+
TestStatus::Passed => "⭐️",
99+
TestStatus::Failed => "❌",
100+
},
101+
match day.part2 {
102+
TestStatus::Missing => "",
103+
TestStatus::Passed => "⭐️",
104+
TestStatus::Failed => "❌",
105+
}
106+
));
107+
}
108+
109+
table
110+
}
111+
fn main() {
112+
let days = get_days();
113+
let table = build_markdown_table(days);
114+
115+
let readme = std::fs::read_to_string("README.md").unwrap();
116+
let re = regex::Regex::new(
117+
r"(?s)(?<pre>.*)<!---Results Table BEGIN-->(.*)<!---Results Table END-->(?<post>.*)$",
118+
)
119+
.unwrap();
120+
let captures = re.captures(&readme).unwrap();
121+
let pre = captures.name("pre").unwrap().as_str();
122+
let post = captures.name("post").unwrap().as_str();
123+
124+
let new_readme = format!(
125+
"{}<!---Results Table BEGIN-->\n## Status\n{}<!---Results Table END-->{}",
126+
pre, table, post
127+
);
128+
129+
std::fs::write("README.md", new_readme).unwrap();
130+
}

src/day01/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ mod tests {
6767
}
6868

6969
#[test]
70-
fn test_part_1() {
70+
fn test_part1() {
7171
let (lhs, rhs) = util_parse::<(Vec<i32>, Vec<i32>)>("day01", "puzzle.txt", parse_input);
7272
let distance = get_distance(lhs, rhs);
7373
println!("Distance: {}", distance);
7474
}
7575

7676
#[test]
77-
fn test_part_2() {
77+
fn test_part2() {
7878
let (lhs, rhs) = util_parse::<(Vec<i32>, Vec<i32>)>("day01", "puzzle.txt", parse_input);
7979
let similarity = get_similarity(lhs, rhs);
8080
println!("Similarity: {}", similarity);

src/day10/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mod tests {
8383
}
8484

8585
#[test]
86-
fn test_part_1() {
86+
fn test_part1() {
8787
let grid = util_parse::<Grid<char>>("day10", "puzzle.txt", Grid::from);
8888
let score = map_score(&grid, trailhead_score);
8989
assert_eq!(score, 430);

src/day12/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod tests {
129129
}
130130

131131
#[test]
132-
fn test_part_1() {
132+
fn test_part1() {
133133
let input = util_parse::<Grid<char>>("day12", "puzzle.txt", parse_input);
134134
let regions = find_regions(&input);
135135
let price = price_regions_by_edges(&regions);

0 commit comments

Comments
 (0)