Finished PE 099, usings logs it was quite easy

This commit is contained in:
2023-06-28 15:31:56 +02:00
parent b4f2968846
commit fdf044144f
3 changed files with 1054 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
use nom::{
bytes::complete::tag,
character::complete::{multispace1, u64},
multi::separated_list1,
sequence::separated_pair,
IResult,
};
use std::{cmp::Ordering, time::Instant};
fn parse_input(input: &str) -> IResult<&str, Vec<(u64, u64)>> {
let (input, result) = separated_list1(multispace1, separated_pair(u64, tag(","), u64))(input)?;
return Ok((input, result));
}
fn compare(a: &(u64, u64), b: &(u64, u64)) -> Ordering {
return (a.1 as f64 * (a.0 as f64).log2()).total_cmp(&(b.1 as f64 * (b.0 as f64).log2()));
}
fn main() {
println!("Hello, this is Patrick!");
let now = Instant::now();
let input_text = include_str!("base_exp.txt");
let (_, base_exps) = parse_input(input_text).unwrap();
let mut line = 1;
let mut result = line;
let mut biggest_n = (0, 0);
for n in base_exps {
match compare(&n, &biggest_n) {
Ordering::Greater => {
biggest_n = n;
result = line;
}
_ => {}
};
line += 1;
}
println!("The biggest number is written on line {}", result);
println!("Time passed: {:?}", Instant::now() - now);
}