Using structures instead

[?]
Jul 11, 2020, 6:30 PM
ES2PMPT47CHTONTR7GAYXTU5LURMPC5W5BQ3YGOXMXT57NZHVHJQC

Dependencies

Change contents

  • replacement in src/main.rs at line 8
    [3.133][2.186:214]()
    // Define a plank structure
    [3.133]
    [2.214]
    // Define a plank piece structure
  • edit in src/main.rs at line 13
    [2.283]
    [2.283]
    }
    // 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);
    }
  • edit in src/main.rs at line 36
    [2.286]
    [3.133]
    // 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);
    }
    }
  • replacement in src/main.rs at line 68
    [3.187][2.400:426](),[2.426][3.62:116](),[3.209][3.62:116](),[3.116][2.427:474]()
    let mut leftover = 0;
    let mut coverage = 0;
    let mut plankcount = 0;
    let mut rowlist: Vec<Vec<Plank>> = vec![];
    [3.187]
    [3.296]
    //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
    [2.538]
    [3.354]
    let finished_floor = build_floor(floor);
    println!("Floor: {:#?}", finished_floor);
    }
  • replacement in src/main.rs at line 86
    [3.355][2.539:637]()
    while coverage < ROOMDEPTH {
    // Create new plank vector
    let mut row = vec![];
    [3.355]
    [3.449]
    fn build_floor(mut floor: Floor) -> Floor {
    floor.add(build_row());
  • replacement in src/main.rs at line 89
    [3.450][2.638:1129]()
    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;
    [3.450]
    [3.556]
    floor
    }
  • replacement in src/main.rs at line 92
    [3.557][2.1130:1229]()
    // For each iteration, we have used another plank
    plankcount += 1;
    [3.557]
    [3.644]
    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![];
  • replacement in src/main.rs at line 106
    [3.645][2.1230:1324]()
    // If a whole plank was used, the leftover is 0
    leftover = 0;
    [3.645]
    [3.746]
    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;
  • replacement in src/main.rs at line 119
    [3.747][2.1325:1667]()
    // 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;
    [3.747]
    [3.964]
    // For each iteration, we have used another plank
    plankcount += 1;
    // If a whole plank was used, the leftover is 0
    leftover = 0;
  • replacement in src/main.rs at line 125
    [3.965][2.1668:1801]()
    // Calculate the leftover plank length
    leftover = PLANKMAX - (ROOMLENGTH - rowfilled);
    }
    [3.965]
    [3.1077]
    // 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;
  • replacement in src/main.rs at line 135
    [3.1078][2.1802:1846]()
    let mut leftoverold = leftover;
    [3.1078]
    [3.1078]
    // Calculate the leftover plank length
    leftover = PLANKMAX - (ROOMLENGTH - rowfilled);
  • edit in src/main.rs at line 138
    [3.1088][2.1847:1874]()
    rowlist.push(row);
  • replacement in src/main.rs at line 139
    [3.1089][3.1089:1173]()
    // How much of the floor have been covered?
    coverage += PLANKWIDTH;
    [3.1089]
    [3.1257]
    let mut leftoverold = leftover;
  • replacement in src/main.rs at line 141
    [3.1263][3.1263:1323](),[3.1323][2.1875:1913]()
    println!("\nTotal amount of planks: {}\n", plankcount);
    println!("\n: {:#?}\n", rowlist);
    [3.1263]
    [3.1323]
    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
    [3.1324][2.1914:1921](),[2.1921][3.1324:1442](),[3.1324][3.1324:1442]()
    /*
    for x in 0..plankcount {
    if planklist[x].0 == ROOMLENGTH {
    println!("|{:-^22}|", ROOMLENGTH);
    [3.1324]
    [3.1442]
    /*
    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)
  • replacement in src/main.rs at line 161
    [3.1459][3.1459:1862]()
    // 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)
    }
    [3.1459]
    [3.1862]
    println!("|{:-^13}||{:-^7}|", planklist[x].0, planklist[x].1)
  • edit in src/main.rs at line 164
    [3.1878][3.1878:1923](),[3.1923][2.1922:1929]()
    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!");
    */