Skip to content

Commit 76edb8c

Browse files
committed
refactor get_solved_ids() according to current logic
1 parent 125c64c commit 76edb8c

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/main.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,12 @@ fn generate_random_id(except_ids: &[u32]) -> u32 {
163163
}
164164

165165
fn get_solved_ids() -> Vec<u32> {
166-
let paths = fs::read_dir("./src/problem").unwrap();
167-
let mut solved_ids = Vec::new();
168-
169-
for path in paths {
170-
let path = path.unwrap().path();
171-
let s = path.to_str().unwrap();
172-
if !s.starts_with('n') {
173-
continue;
174-
}
175-
let id = &s[7..11];
176-
let id = id.parse::<u32>().unwrap();
177-
solved_ids.push(id);
178-
}
179-
solved_ids
166+
let content = fs::read_to_string("./src/problem/mod.rs").unwrap();
167+
let id_pattern = Regex::new(r"p(\d{4})_").unwrap();
168+
id_pattern
169+
.captures_iter(&content)
170+
.map(|x| x.get(1).unwrap().as_str().parse().unwrap())
171+
.collect()
180172
}
181173

182174
fn parse_extra_use(code: &str) -> String {

0 commit comments

Comments
 (0)