Skip to content

Commit

Permalink
Fix various type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 18, 2024
1 parent 43327bb commit 0bf99db
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rust/src/p0001.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub fn p0001() -> i128 {
for i in (0..1000).step_by(15) {
answer -= i;
}
return answer;
return answer.into();
}
2 changes: 1 addition & 1 deletion rust/src/p0002.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub fn p0002() -> i128 {
i = j;
j = tmp;
}
return answer;
return answer.into();
}
5 changes: 4 additions & 1 deletion rust/src/p0003.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ What is the largest prime factor of the number 600851475143 ?
use crate::primes::prime_factors;

pub fn p0003() -> i128 {
return prime_factors::<u64>(600851475143).max().expect("This number has prime factors");
return prime_factors::<u64>(600851475143)
.max()
.expect("This number has prime factors")
.into();
}
6 changes: 3 additions & 3 deletions rust/src/p0004.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ Find the largest palindrome made from the product of two 3-digit numbers.
*/
use itertools::Itertools;

fn is_palindrome(x: u64) -> bool {
fn is_palindrome(x: u32) -> bool {
let s = x.to_string();
return s == s.chars().rev().collect::<String>();
}

pub fn p0004() -> i128 {
let mut answer: u32 = 0;
for v in (100..1000).combinations(2) {
let p = v.into_iter().product();
let p: u32 = v.into_iter().product();
if is_palindrome(p) && p > answer {
answer = p;
}
}
return answer;
return answer.into();
}

2 changes: 1 addition & 1 deletion rust/src/p0005.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub fn p0005() -> i128 {
}
}
}
return answer;
return answer.into();
}
2 changes: 1 addition & 1 deletion rust/src/p0006.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub fn p0006() -> i128 {
let sum_of_squares = group.clone().fold(0, |x, y| x + y * y);
let sum: u32 = group.sum();
let square_of_sum = sum * sum;
return square_of_sum - sum_of_squares;
return (square_of_sum - sum_of_squares).into();
}
6 changes: 5 additions & 1 deletion rust/src/p0007.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ What is the 10 001st prime number?
use crate::primes::primes;

pub fn p0007() -> i128 {
return primes::<u32>().take(10001).last().unwrap();
return primes::<u32>()
.take(10001)
.last()
.unwrap()
.into();
}
2 changes: 1 addition & 1 deletion rust/src/p0008.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ pub fn p0008() -> i128 {
answer = prod;
}
}
return answer;
return answer.into();
}
2 changes: 1 addition & 1 deletion rust/src/p0009.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn p0009() -> i128 {
for a in 1..b {
let a_square = a * a;
if a_square + b_square == c_square && a + b + c == 1000 {
return a * b * c;
return (a * b * c).into();
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion rust/src/p0010.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ Find the sum of all the primes below two million.
use crate::primes::primes;

pub fn p0010() -> i128 {
return primes::<u64>().take_while(|&p| p < 2000000).sum();
return primes::<u64>()
.take_while(|&p| p < 2000000)
.sum()
.into();
}

0 comments on commit 0bf99db

Please sign in to comment.