generated from janezicmatej/aoc-template
	solution: day 6 clean
This commit is contained in:
		@@ -1,5 +1,3 @@
 | 
				
			|||||||
use aoc::parsers::to_vec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn win_options((time, distance): (u64, u64)) -> u64 {
 | 
					fn win_options((time, distance): (u64, u64)) -> u64 {
 | 
				
			||||||
    let discriminant = ((time.pow(2) - 4 * distance) as f64).sqrt();
 | 
					    let discriminant = ((time.pow(2) - 4 * distance) as f64).sqrt();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -14,28 +12,34 @@ fn win_options((time, distance): (u64, u64)) -> u64 {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn part_one(input: &str) -> Option<u64> {
 | 
					pub fn part_one(input: &str) -> Option<u64> {
 | 
				
			||||||
    let (upt, upd) = input.split_once('\n')?;
 | 
					    let [time, distance] = input
 | 
				
			||||||
    let time: Vec<u64> = to_vec(upt.strip_prefix("Time:      ")?, ' ');
 | 
					        .lines()
 | 
				
			||||||
    let distance: Vec<u64> = to_vec(upd.strip_prefix("Distance:  ")?, ' ');
 | 
					        .map(|l| {
 | 
				
			||||||
 | 
					            l.split_whitespace()
 | 
				
			||||||
 | 
					                .skip(1)
 | 
				
			||||||
 | 
					                .filter_map(|n| n.parse().ok())
 | 
				
			||||||
 | 
					                .collect::<Vec<u64>>()
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        .collect::<Vec<_>>()
 | 
				
			||||||
 | 
					        .try_into()
 | 
				
			||||||
 | 
					        .ok()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Some(time.into_iter().zip(distance).map(win_options).product())
 | 
					    Some(time.into_iter().zip(distance).map(win_options).product())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn part_two(input: &str) -> Option<u64> {
 | 
					pub fn part_two(input: &str) -> Option<u64> {
 | 
				
			||||||
    let (upt, upd) = input.split_once('\n')?;
 | 
					    let [time, distance] = input
 | 
				
			||||||
    let time: u64 = upt
 | 
					        .lines()
 | 
				
			||||||
        .strip_prefix("Time:      ")?
 | 
					        .filter_map(|l| {
 | 
				
			||||||
        .split(' ')
 | 
					            l.split_whitespace()
 | 
				
			||||||
        .flat_map(|x| x.chars())
 | 
					                .skip(1)
 | 
				
			||||||
        .collect::<String>()
 | 
					 | 
				
			||||||
        .parse()
 | 
					 | 
				
			||||||
        .ok()?;
 | 
					 | 
				
			||||||
    let distance: u64 = upd
 | 
					 | 
				
			||||||
        .strip_prefix("Distance:  ")?
 | 
					 | 
				
			||||||
        .split(' ')
 | 
					 | 
				
			||||||
                .flat_map(|x| x.chars())
 | 
					                .flat_map(|x| x.chars())
 | 
				
			||||||
                .collect::<String>()
 | 
					                .collect::<String>()
 | 
				
			||||||
                .parse()
 | 
					                .parse()
 | 
				
			||||||
 | 
					                .ok()
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        .collect::<Vec<_>>()
 | 
				
			||||||
 | 
					        .try_into()
 | 
				
			||||||
        .ok()?;
 | 
					        .ok()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Some(win_options((time, distance)))
 | 
					    Some(win_options((time, distance)))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user