Doing some C learnin'.
Also, reformatted all the problems.
This commit is contained in:
42
2016/day01/day01.rs
Normal file
42
2016/day01/day01.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user