analyse() now returns the correct values for the crates vector.
This commit is contained in:
parent
b94278d500
commit
a823166659
1 changed files with 26 additions and 10 deletions
|
@ -1,11 +1,11 @@
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
fn analyse(str: &String) -> (u32, Vec<(u32, u32, u32)>, Vec<Vec<&str>>) {
|
fn analyse(str: &String) -> (u32, Vec<(u32, u32, u32)>, Vec<Vec<char>>) {
|
||||||
// Initializing some values.
|
// Initializing some values.
|
||||||
let mut info: Vec<_> = str.split("\r\n").collect();
|
let mut info: Vec<_> = str.split("\r\n").collect();
|
||||||
let mut crates: &[&str] = &[""];
|
let mut crates: &[&str] = &[""];
|
||||||
let mut cmd: &[&str] = &[""];
|
let mut cmd: &[&str] = &[""];
|
||||||
let mut crates_str: Vec<Vec<&str>> = Vec::new();
|
let mut crates_str: Vec<Vec<char>> = Vec::new();
|
||||||
let mut commands_tuple: Vec<(u32, u32, u32)> = Vec::new();
|
let mut commands_tuple: Vec<(u32, u32, u32)> = Vec::new();
|
||||||
|
|
||||||
// Spliting the str into a cmd part, and crates part.
|
// Spliting the str into a cmd part, and crates part.
|
||||||
|
@ -26,25 +26,41 @@ fn analyse(str: &String) -> (u32, Vec<(u32, u32, u32)>, Vec<Vec<&str>>) {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Gathering each crate Letters
|
// Gathering each crate Letters
|
||||||
for (i, str) in crates.iter().enumerate() {
|
for _i in 0..max_crates.iter().max().unwrap().to_owned() {
|
||||||
if i == crates.len()-1 {
|
crates_str.push(Vec::new());
|
||||||
break;
|
}
|
||||||
|
for (i, str) in crates.iter().rev().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for y in 0..max_crates.iter().max().unwrap().to_owned() {
|
||||||
|
let ch = str.as_bytes()[((y*4)+1) as usize];
|
||||||
|
if ch != (' ' as u8) {
|
||||||
|
crates_str[y as usize].push(ch as char);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
crates_str.push(str.split_whitespace().collect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rearanging commands as simplier datatypes to process.
|
// Rearanging commands as simplier datatypes to process.
|
||||||
for str in cmd {
|
for str in cmd {
|
||||||
let str_temp : Vec<&str> = str.split_whitespace().collect();
|
let tuple_temp: Vec<Option<u32>> = str
|
||||||
let tuple_temp : Vec<Option<u32>> = str_temp.iter().map_while(|str| Some(str.parse().ok())).collect();
|
.split_whitespace()
|
||||||
commands_tuple.push((tuple_temp[1].unwrap(), tuple_temp[3].unwrap(), tuple_temp[5].unwrap()));
|
.collect::<Vec<&str>>()
|
||||||
|
.iter()
|
||||||
|
.map_while(|str| Some(str.parse().ok()))
|
||||||
|
.collect();
|
||||||
|
commands_tuple.push((
|
||||||
|
tuple_temp[1].unwrap(),
|
||||||
|
tuple_temp[3].unwrap(),
|
||||||
|
tuple_temp[5].unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returning every info as a tuple
|
// Returning every info as a tuple
|
||||||
(
|
(
|
||||||
max_crates.iter().max().unwrap().to_owned(),
|
max_crates.iter().max().unwrap().to_owned(),
|
||||||
commands_tuple.to_owned(),
|
commands_tuple.to_owned(),
|
||||||
crates_str.to_owned()
|
crates_str.to_owned(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue