ES2PMPT47CHTONTR7GAYXTU5LURMPC5W5BQ3YGOXMXT57NZHVHJQC
}
// Define a row structure
#[derive(Debug)]
struct Row {
planks: Vec<Plank>,
full: bool,
}
impl Row {
/// Is this row considered complete?
fn is_full(&self) -> bool {
self.full
}
/// Get the number of plank rows for this floor
fn rows_count(&self) -> usize {
self.planks.len()
}
fn add(&mut self, plank: Plank) -> () {
self.planks.push(plank);
}
// Define a floor structure
#[derive(Debug)]
struct Floor {
rows: Vec<Row>,
complete: bool,
}
impl Floor {
/// Is this floor considered complete?
fn is_complete(&self) -> bool {
self.complete
}
/// Get the number of plank rows for this floor
fn rows_count(&self) -> usize {
self.rows.len()
}
fn add(&mut self, row: Row) -> () {
self.rows.push(row);
}
}
let mut leftover = 0;
let mut coverage = 0;
let mut plankcount = 0;
let mut rowlist: Vec<Vec<Plank>> = vec![];
//let mut leftover = 0;
//let mut coverage = 0;
//let mut plankcount = 0;
//let mut rowlist: Vec<Vec<Plank>> = vec![];
let row = Row {
planks: vec![],
full: false,
};
let floor = Floor {
rows: vec![row],
complete: false,
};
let mut rowfilled = 0;
while rowfilled < ROOMLENGTH {
// Length of the plank is greater than the remainder room
if ROOMLENGTH - rowfilled > PLANKMAX {
// If this is the first plank
let end = rowfilled == 0;
// Store the full length plank
row.push(Plank {
length: PLANKMAX,
endpiece: end,
});
rowfilled += PLANKMAX;
floor
}
// For each iteration, we have used another plank
plankcount += 1;
fn build_row() -> Row {
Row {
planks: vec![],
full: false,
}
}
fn calc_new_length(prev: u32, next: u32) -> u32 {
prev - next
}
/*
while coverage < ROOMDEPTH {
// Create new plank vector
let mut row = vec![];
// If a whole plank was used, the leftover is 0
leftover = 0;
let mut rowfilled = 0;
while rowfilled < ROOMLENGTH {
// Length of the plank is greater than the remainder room
if ROOMLENGTH - rowfilled > PLANKMAX {
// If this is the first plank
let end = rowfilled == 0;
// Store the full length plank
row.push(Plank {
length: PLANKMAX,
endpiece: end,
});
rowfilled += PLANKMAX;
// Length of the plank is smaller than the room
} else {
// Add the remainder
let remainder = ROOMLENGTH - rowfilled;
row.push(Plank {
length: remainder,
endpiece: true,
});
rowfilled += remainder;
// For each iteration, we have used another plank
plankcount += 1;
// If a whole plank was used, the leftover is 0
leftover = 0;
// Calculate the leftover plank length
leftover = PLANKMAX - (ROOMLENGTH - rowfilled);
}
// Length of the plank is smaller than the room
} else {
// Add the remainder
let remainder = ROOMLENGTH - rowfilled;
row.push(Plank {
length: remainder,
endpiece: true,
});
rowfilled += remainder;
println!("\nTotal amount of planks: {}\n", plankcount);
println!("\n: {:#?}\n", rowlist);
rowlist.push(row);
// How much of the floor have been covered?
coverage += PLANKWIDTH;
}
*/
//println!("\nTotal amount of planks: {}\n", plankcount);
//println!("\n: {:#?}\n", rowlist);
/*
for x in 0..plankcount {
if planklist[x].0 == ROOMLENGTH {
println!("|{:-^22}|", ROOMLENGTH);
/*
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)
// 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!("|{:-^13}||{:-^7}|", planklist[x].0, planklist[x].1)