simplify rust code somewhat
This commit is contained in:
parent
5809d442da
commit
5426357cd7
22
07/main.rs
22
07/main.rs
@ -42,20 +42,17 @@ fn part_one() {
|
||||
if f < 100000 {
|
||||
sum += f
|
||||
}
|
||||
let mut p = stack.pop().unwrap();
|
||||
p += f;
|
||||
stack.push(p);
|
||||
let last_on_stack = stack.len() - 1;
|
||||
stack[last_on_stack] += f;
|
||||
}
|
||||
s if s.starts_with("$ cd ") => {
|
||||
stack.push(0);
|
||||
}
|
||||
s => {
|
||||
// otherwise it must be a file
|
||||
let mut f = stack.pop().unwrap();
|
||||
let mut sp = s.split(" ");
|
||||
let size = sp.next().unwrap().parse::<u32>().unwrap();
|
||||
f += size;
|
||||
stack.push(f);
|
||||
let last_on_stack = stack.len() - 1;
|
||||
stack[last_on_stack] += sp.next().unwrap().parse::<u32>().unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -80,20 +77,17 @@ fn part_two() {
|
||||
if f > space_to_free && f < to_delete {
|
||||
to_delete = f
|
||||
}
|
||||
let mut p = stack.pop().unwrap();
|
||||
p += f;
|
||||
stack.push(p);
|
||||
let last_on_stack = stack.len() - 1;
|
||||
stack[last_on_stack] += f;
|
||||
}
|
||||
s if s.starts_with("$ cd ") => {
|
||||
stack.push(0);
|
||||
}
|
||||
s => {
|
||||
// otherwise it must be a file
|
||||
let mut f = stack.pop().unwrap();
|
||||
let mut sp = s.split(" ");
|
||||
let size = sp.next().unwrap().parse::<u32>().unwrap();
|
||||
f += size;
|
||||
stack.push(f);
|
||||
let last_on_stack = stack.len() - 1;
|
||||
stack[last_on_stack] += sp.next().unwrap().parse::<u32>().unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user