Using structures instead
[?]
Jul 11, 2020, 6:30 PM
ES2PMPT47CHTONTR7GAYXTU5LURMPC5W5BQ3YGOXMXT57NZHVHJQCDependencies
- [2]
2USDM5CHWIP for more generic - [3]
RXRHPE7SSovrummet - [4]
3H2BGWRGWIP - [5]
F3GMCMWTMerge branch 'master' into sovrum - [6]
5TH3AA4610 mm extra space - [7]
UPCMFGXFPrint more about the room and define PLAY
Change contents
- replacement in src/main.rs at line 8
// Define a plank structure// Define a plank piece structure - edit in src/main.rs at line 13
}// 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 floorfn rows_count(&self) -> usize {self.planks.len()}fn add(&mut self, plank: Plank) -> () {self.planks.push(plank);} - edit in src/main.rs at line 36
// 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 floorfn rows_count(&self) -> usize {self.rows.len()}fn add(&mut self, row: Row) -> () {self.rows.push(row);}} - replacement in src/main.rs at line 68
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,}; - edit in src/main.rs at line 82
let finished_floor = build_floor(floor);println!("Floor: {:#?}", finished_floor);} - replacement in src/main.rs at line 86
while coverage < ROOMDEPTH {// Create new plank vectorlet mut row = vec![];fn build_floor(mut floor: Floor) -> Floor {floor.add(build_row()); - replacement in src/main.rs at line 89
let mut rowfilled = 0;while rowfilled < ROOMLENGTH {// Length of the plank is greater than the remainder roomif ROOMLENGTH - rowfilled > PLANKMAX {// If this is the first planklet end = rowfilled == 0;// Store the full length plankrow.push(Plank {length: PLANKMAX,endpiece: end,});rowfilled += PLANKMAX;floor} - replacement in src/main.rs at line 92
// For each iteration, we have used another plankplankcount += 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 vectorlet mut row = vec![]; - replacement in src/main.rs at line 106
// If a whole plank was used, the leftover is 0leftover = 0;let mut rowfilled = 0;while rowfilled < ROOMLENGTH {// Length of the plank is greater than the remainder roomif ROOMLENGTH - rowfilled > PLANKMAX {// If this is the first planklet end = rowfilled == 0;// Store the full length plankrow.push(Plank {length: PLANKMAX,endpiece: end,});rowfilled += PLANKMAX; - replacement in src/main.rs at line 119
// Length of the plank is smaller than the room} else {// Add the remainderlet remainder = ROOMLENGTH - rowfilled;row.push(Plank {length: remainder,endpiece: true,});rowfilled += remainder;// For each iteration, we have used another plankplankcount += 1;// If a whole plank was used, the leftover is 0leftover = 0; - replacement in src/main.rs at line 125
// Calculate the leftover plank lengthleftover = PLANKMAX - (ROOMLENGTH - rowfilled);}// Length of the plank is smaller than the room} else {// Add the remainderlet remainder = ROOMLENGTH - rowfilled;row.push(Plank {length: remainder,endpiece: true,});rowfilled += remainder; - replacement in src/main.rs at line 135
let mut leftoverold = leftover;// Calculate the leftover plank lengthleftover = PLANKMAX - (ROOMLENGTH - rowfilled); - edit in src/main.rs at line 138
rowlist.push(row); - replacement in src/main.rs at line 139
// How much of the floor have been covered?coverage += PLANKWIDTH;let mut leftoverold = leftover; - replacement in src/main.rs at line 141
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); - replacement in src/main.rs at line 150
/*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 oddif 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) - replacement in src/main.rs at line 161
// If x is oddif 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) - edit in src/main.rs at line 164
println!();println!("Lycka till!");*/ - replacement in src/main.rs at line 165[3.1925]→[3.1925:1926](∅→∅),[3.1926]→[2.1930:1980](∅→∅),[2.1980]→[3.1976:1994](∅→∅),[3.1976]→[3.1976:1994](∅→∅)
fn calc_new_length(prev: u32, next: u32) -> u32 {prev - next}[3.1925]println!();println!("Lycka till!");*/