Skip to content

Commit

Permalink
don't collect very large vector
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 30, 2024
1 parent bbc4026 commit d7ddd9f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions rust/src/p0111.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ use crate::include::utils::Answer;
pub fn p0111() -> Answer {
let ten_9: u64 = 10_u64.pow(9);
let ten_10: u64 = 10_u64.pow(10);
let primes_int: Vec<u64> = primes_until::<u64>(ten_10).filter(|x| *x > ten_9).collect();
let primes_str: Vec<String> = primes_int.iter().map(|p| (*p).to_string()).collect();
let mut answer: u64 = 0;
for digit in 0..=9 {
let primes_counts: Vec<usize> = primes_str.iter().map(|s| (*s).bytes().filter(|b| *b == digit + b'0').count()).collect();
let n: usize = primes_counts.iter().map(|x| *x).max().unwrap();
answer += zip(primes_int.iter(), primes_counts.iter()).filter(|(_i, c)| **c == n).map(|(i, _c)| *i).sum::<u64>();
let mut subanswer: Vec<u64> = vec![0; 10];
let mut current: Vec<usize> = vec![0; 10];
for p in primes_until::<u64>(ten_10).filter(|x| *x > ten_9) {
let s = p.to_string();
for digit in 0..=9 {
let count = s.bytes().filter(|b| *b == digit + b'0').count();
if count > current[digit] {

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8
current[digit] = count;

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8
subanswer[digit] = p;

Check failure

Code scanning / clippy

the type [u64] cannot be indexed by u8 Error

the type [u64] cannot be indexed by u8

Check failure

Code scanning / clippy

the type [u64] cannot be indexed by u8 Error

the type [u64] cannot be indexed by u8
} else if count == current[digit] {

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8

Check failure

Code scanning / clippy

the type [usize] cannot be indexed by u8 Error

the type [usize] cannot be indexed by u8
subanswer[digit] += p;

Check failure

Code scanning / clippy

the type [u64] cannot be indexed by u8 Error

the type [u64] cannot be indexed by u8

Check failure

Code scanning / clippy

the type [u64] cannot be indexed by u8 Error

the type [u64] cannot be indexed by u8
}
}
}
return Answer::Int(answer.into());
return Answer::Int(subanswer.into_iter().sum::<u64>().into());
}

0 comments on commit d7ddd9f

Please sign in to comment.