chore: rustfmt
This commit is contained in:
parent
add6f2403c
commit
b7c61ccef8
|
@ -26,5 +26,5 @@ fn main() {
|
||||||
increment += 1;
|
increment += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:?}", primes[primes.len()-1]);
|
println!("{:?}", primes[primes.len() - 1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut sequence: Vec<i32> = vec![1, 2];
|
let mut sequence: Vec<i32> = vec![1, 2];
|
||||||
while sequence[sequence.len()-1] <= 4000000 {
|
while sequence[sequence.len() - 1] <= 4000000 {
|
||||||
let mut last = sequence[sequence.len()-1];
|
let mut last = sequence[sequence.len() - 1];
|
||||||
let mut secondlast = sequence[sequence.len()-2];
|
let mut secondlast = sequence[sequence.len() - 2];
|
||||||
(secondlast, last) = (last, secondlast+last);
|
(secondlast, last) = (last, secondlast + last);
|
||||||
sequence.push(last);
|
sequence.push(last);
|
||||||
}
|
}
|
||||||
for i in sequence.clone() {
|
for i in sequence.clone() {
|
||||||
if i % 2 != 0 || i > 4000000 {
|
if i % 2 != 0 || i > 4000000 {
|
||||||
sequence.remove(sequence.iter().position(|x| *x == i).expect("Item not found"));
|
sequence.remove(
|
||||||
|
sequence
|
||||||
|
.iter()
|
||||||
|
.position(|x| *x == i)
|
||||||
|
.expect("Item not found"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sum: i32 = sequence.iter().sum();
|
let sum: i32 = sequence.iter().sum();
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub fn factors(num: u64) -> Vec<u64> {
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut triangular_increment: u64 = 0;
|
let mut triangular_increment: u64 = 0;
|
||||||
let mut triangular: u64 = 0;
|
let mut triangular: u64 = 0;
|
||||||
|
|
||||||
while factors(triangular).len() <= 500 {
|
while factors(triangular).len() <= 500 {
|
||||||
triangular = 0;
|
triangular = 0;
|
||||||
for i in 1..=triangular_increment {
|
for i in 1..=triangular_increment {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut product: i64 = 0;
|
let mut product: i64 = 0;
|
||||||
|
|
||||||
for i in 1..=999 {
|
for i in 1..=999 {
|
||||||
for j in 1..=999 {
|
for j in 1..=999 {
|
||||||
let product_string: String = format!("{:?}", i*j);
|
let product_string: String = format!("{:?}", i * j);
|
||||||
let reversed_string = product_string.chars().rev().collect::<String>();
|
let reversed_string = product_string.chars().rev().collect::<String>();
|
||||||
|
|
||||||
if i*j > product && reversed_string == product_string {
|
if i * j > product && reversed_string == product_string {
|
||||||
product = i*j;
|
product = i * j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", product);
|
println!("{}", product);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ fn main() {
|
||||||
let mut factors: Vec<u64> = vec![];
|
let mut factors: Vec<u64> = vec![];
|
||||||
let mut i: u64 = 2;
|
let mut i: u64 = 2;
|
||||||
while i.pow(2) <= num {
|
while i.pow(2) <= num {
|
||||||
if num % i == 0 {
|
if num % i == 0 {
|
||||||
factors.push(i);
|
factors.push(i);
|
||||||
num = (num as f64 / i as f64).floor() as u64;
|
num = (num as f64 / i as f64).floor() as u64;
|
||||||
} else {
|
} else {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if num != 1 {
|
if num != 1 {
|
||||||
factors.push(num);
|
factors.push(num);
|
||||||
|
|
|
@ -5,8 +5,8 @@ fn main() {
|
||||||
for k in 1..1000 {
|
for k in 1..1000 {
|
||||||
let pythagoras: f64 = (i as f64).powf(2.) + (j as f64).powf(2.);
|
let pythagoras: f64 = (i as f64).powf(2.) + (j as f64).powf(2.);
|
||||||
if pythagoras == (k as f64).powf(2.) {
|
if pythagoras == (k as f64).powf(2.) {
|
||||||
if i+j+k == 1000 {
|
if i + j + k == 1000 {
|
||||||
println!("{}", i*j*k);
|
println!("{}", i * j * k);
|
||||||
break 'algorithm;
|
break 'algorithm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ fn main() {
|
||||||
let mut total1: u64 = 0;
|
let mut total1: u64 = 0;
|
||||||
|
|
||||||
for i in 1..=100 {
|
for i in 1..=100 {
|
||||||
total += i*i;
|
total += i * i;
|
||||||
total1 += i;
|
total1 += i;
|
||||||
}
|
}
|
||||||
|
|
||||||
let square_sum = total1.pow(2);
|
let square_sum = total1.pow(2);
|
||||||
let difference = square_sum-total;
|
let difference = square_sum - total;
|
||||||
|
|
||||||
println!("{}", difference);
|
println!("{}", difference);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue