2016/15
This commit is contained in:
4
2016/15/Cargo.lock
generated
Normal file
4
2016/15/Cargo.lock
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[root]
|
||||||
|
name = "15"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
6
2016/15/Cargo.toml
Normal file
6
2016/15/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "15"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
53
2016/15/src/main.rs
Normal file
53
2016/15/src/main.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use std::usize;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn calculate_time(discs: &Vec<(usize, usize)>) -> Result<usize, ()> {
|
||||||
|
'main: for t in 0..usize::MAX {
|
||||||
|
for (i, &(p, m)) in discs.iter().enumerate() {
|
||||||
|
if (t + i + 1 + p) % m != 0 {
|
||||||
|
continue 'main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let time_1 = calculate_time(&vec![
|
||||||
|
(2, 5),
|
||||||
|
(7, 13),
|
||||||
|
(10, 17),
|
||||||
|
(2, 3),
|
||||||
|
(9, 19),
|
||||||
|
(0, 7)
|
||||||
|
]);
|
||||||
|
|
||||||
|
println!("time_1={:?}", time_1);
|
||||||
|
|
||||||
|
let time_2 = calculate_time(&vec![
|
||||||
|
(2, 5),
|
||||||
|
(7, 13),
|
||||||
|
(10, 17),
|
||||||
|
(2, 3),
|
||||||
|
(9, 19),
|
||||||
|
(0, 7),
|
||||||
|
(0, 11)
|
||||||
|
]);
|
||||||
|
|
||||||
|
println!("time_2={:?}", time_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn example_01() {
|
||||||
|
assert_eq!(Ok(5), calculate_time(&vec![(4, 5), (1, 2)]));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user