Skip to content

Commit 1c30fad

Browse files
committed
merci patrik
1 parent b85f7f1 commit 1c30fad

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/day5.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ pub struct Rules {
1111
pub fn input_generator(input: &str) -> Rules {
1212
let mut ordering = HashMap::new();
1313
let mut updates = vec![];
14+
let (one, two) = input.split_once("\n\n").unwrap();
1415

15-
for l in input.lines() {
16-
if l.contains("|") {
17-
let sides = l.split_once("|").unwrap();
18-
ordering
19-
.entry(sides.1.parse().unwrap())
20-
.or_insert_with(Vec::new)
21-
.push(sides.0.parse().unwrap());
22-
}
23-
if l.contains(",") {
24-
updates.push(l.split(",").map(|s| s.parse().unwrap()).collect());
25-
}
16+
for l in one.lines() {
17+
let sides = l.split_once("|").unwrap();
18+
ordering
19+
.entry(sides.1.parse().unwrap())
20+
.or_insert_with(Vec::new)
21+
.push(sides.0.parse().unwrap());
22+
}
23+
for l in two.lines() {
24+
updates.push(l.split(",").map(|s| s.parse().unwrap()).collect());
2625
}
2726
Rules { ordering, updates }
2827
}
@@ -65,7 +64,6 @@ pub fn part2(input: &Rules) -> usize {
6564
for invalid in invalids {
6665
let mut inv = invalid.clone();
6766
inv.sort_by(|a, b| {
68-
dbg!(a, b);
6967
if let Some(must_be_before) = input.ordering.get(b) {
7068
if must_be_before.contains(a) {
7169
return Ordering::Less;

0 commit comments

Comments
 (0)