static PLANKMAX: i32 = 2200;
static PLANKWIDTH: i32 = 185;
static ROOMLENGTH: i32 = 1600 - 20;
static ROOMDEPTH: i32 = 1200 - 20;
fn main() {
println!("Halloj golvläggare!)\n");
let mut temp = 0;
let mut coverage = 70;
let mut plankcount = 1;
let mut planklist = vec![];
temp = calc_new_length(PLANKMAX, ROOMLENGTH - temp);
println!("First plank length: {}", PLANKMAX - temp);
planklist.push((ROOMLENGTH, 0));
while coverage < ROOMDEPTH {
// Store the old length for the list
let tempold = temp;
// Length of the plank is greater than the room
if temp > ROOMLENGTH {
// Store the full length plank and the next
planklist.push((ROOMLENGTH, 0));
temp -= ROOMLENGTH;
// Length of the plank is smaller than the room
} else {
// Store the two plank lengths as a tuple
planklist.push((tempold, ROOMLENGTH - temp));
// Calculate the next plank length
temp = calc_new_length(PLANKMAX, ROOMLENGTH - temp);
}
// How much of the floor have been covered?
coverage += PLANKWIDTH;
// For each iteration, we have added another plank
plankcount += 1;
}
println!("\nTotal amount of planks: {}\n", plankcount);
for x in 0..plankcount {
if planklist[x].0 == ROOMLENGTH {
println!("|{:-^22}|", ROOMLENGTH);
} else {
// If x is odd
if planklist[x].0 == planklist[x].1 {
println!("|{:-^10}||{:-^10}|", planklist[x].0, planklist[x].1)
} else if planklist[x].0 < planklist[x].1 {
println!("|{:-^7}||{:-^13}|", planklist[x].0, planklist[x].1)
} else {
println!("|{:-^13}||{:-^7}|", planklist[x].0, planklist[x].1)
}
}
}
println!();
println!("Lycka till!");
}
fn calc_new_length(prev: i32, next: i32) -> i32 {
prev - next
}