|
@@ -1,7 +1,9 @@
|
|
|
|
|
+use std::env;
|
|
|
use std::fs::File;
|
|
use std::fs::File;
|
|
|
use std::io::{BufReader,BufRead};
|
|
use std::io::{BufReader,BufRead};
|
|
|
|
|
|
|
|
fn main() {
|
|
fn main() {
|
|
|
|
|
+ let args: Vec<String> = env::args().collect();
|
|
|
let filename = "input.txt";
|
|
let filename = "input.txt";
|
|
|
let file = File::open(filename).unwrap();
|
|
let file = File::open(filename).unwrap();
|
|
|
let reader = BufReader::new(file);
|
|
let reader = BufReader::new(file);
|
|
@@ -34,7 +36,11 @@ fn main() {
|
|
|
let ammount = parts[1].parse::<i32>().unwrap();
|
|
let ammount = parts[1].parse::<i32>().unwrap();
|
|
|
let from = parts[3].parse::<usize>().unwrap();
|
|
let from = parts[3].parse::<usize>().unwrap();
|
|
|
let to = parts[5].parse::<usize>().unwrap();
|
|
let to = parts[5].parse::<usize>().unwrap();
|
|
|
- r#move(ammount,from,to,&mut containers);
|
|
|
|
|
|
|
+ if args[1] == "1"{
|
|
|
|
|
+ r#move(ammount,from,to,&mut containers);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ r#move_as_stack(ammount,from,to,&mut containers);
|
|
|
|
|
+ }
|
|
|
println!("{line}");
|
|
println!("{line}");
|
|
|
print_containers(&containers);
|
|
print_containers(&containers);
|
|
|
}
|
|
}
|
|
@@ -69,6 +75,16 @@ fn r#move(ammount: i32,from: usize, to: usize, containers: &mut [Vec<char>;9]){
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+fn move_as_stack(ammount: i32,from: usize, to: usize, containers: &mut [Vec<char>;9]){
|
|
|
|
|
+ let mut crane: Vec<char> = Vec::new();
|
|
|
|
|
+ for i in 0..ammount{
|
|
|
|
|
+ crane.push(containers[from - 1].pop().unwrap());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for i in 0..ammount{
|
|
|
|
|
+ containers[to - 1].push(crane.pop().unwrap());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
fn fix_containers(con: &mut [Vec<char>;9]){
|
|
fn fix_containers(con: &mut [Vec<char>;9]){
|
|
|
for i in 0..9{
|
|
for i in 0..9{
|