Finished PE 099, usings logs it was quite easy
This commit is contained in:
1000
projecteuler/099/src/base_exp.txt
Normal file
1000
projecteuler/099/src/base_exp.txt
Normal file
File diff suppressed because it is too large
Load Diff
45
projecteuler/099/src/main.rs
Normal file
45
projecteuler/099/src/main.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user