Doing some C learnin'.

Also, reformatted all the problems.
This commit is contained in:
2018-03-15 10:08:01 -05:00
parent 16ffec256f
commit 986d17f104
31 changed files with 1470 additions and 58 deletions

42
2016/day01/day01.rs Normal file
View File

@@ -0,0 +1,42 @@
use std::fmt;
mod helpers;
enum Direction {
North,
East,
South,
West
}
struct Position {
x: i32,
y: i32,
dir: Direction,
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {}: {})", self.x, self.y, string_dir(self.dir))
}
}
fn string_dir(d: Direction) -> String {
match d {
Direction::North => String::from("North"),
Direction::East => String::from("East"),
Direction::South => String::from("South"),
Direction::West => String::from("West"),
}
}
fn main() {
let input = helpers::read_std_in();
let split = input.split(",");
for mut s in split {
s = s.trim();
println!("{}", s);
}
let p = Position{ x: 0, y: 0, dir: Direction::North };
println!("{}", p)
}

20
2016/day01/helpers.rs Normal file
View File

@@ -0,0 +1,20 @@
use std::io;
pub fn read_std_in() -> String {
let mut input = String::new();
let mut done = false;
while !done {
match io::stdin().read_line(&mut input) {
Ok(n) => {
if n == 0 {
done = true;
}
},
Err(error) => {
println!("error: {}", error);
done = true;
},
}
}
input
}

15
2016/day01/input2 Normal file
View File

@@ -0,0 +1,15 @@
R3, L5, R2, L1, L2, R5, L2, R2, L2, L2, L1, R2,
L2, R4, R4, R1, L2, L3, R3, L1, R2, L2, L4, R4,
R5, L3, R3, L3, L3, R4, R5, L3, R3, L5, L1, L2,
R2, L1, R3, R1, L1, R187, L1, R2, R47, L5, L1,
L2, R4, R3, L3, R3, R4, R1, R3, L1, L4, L1, R2,
L1, R4, R5, L1, R77, L5, L4, R3, L2, R4, R5, R5,
L2, L2, R2, R5, L2, R194, R5, L2, R4, L5, L4,
L2, R5, L3, L2, L5, R5, R2, L3, R3, R1, L4, R2,
L1, R5, L1, R5, L1, L1, R3, L1, R5, R2, R5, R5,
L4, L5, L5, L5, R3, L2, L5, L4, R3, R1, R1, R4,
L2, L4, R5, R5, R4, L2, L2, R5, R5, L5, L2, R4,
R4, L4, R1, L3, R1, L1, L1, L1, L4, R5, R4, L4,
L4, R5, R3, L2, L2, R3, R1, R4, L3, R1, L4, R3,
L3, L2, R2, R2, R2, L1, L4, R3, R2, R2, L3, R2,
L3, L2, R4, L2, R3, L4, R5, R4, R1, R5, R3