2015 day 1 (redoing lost challenges)

master
dece 3 years ago
parent 56ec1d2ec7
commit 351fc11bed

1
2015/.gitignore vendored

@ -0,0 +1 @@
target/

5
2015/Cargo.lock generated

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aoc2015"
version = "0.1.0"

@ -0,0 +1,10 @@
[package]
name = "aoc2015"
version = "0.1.0"
authors = ["dece <shgck@pistache.land>"]
edition = "2018"
[lib]
name = "aoc"
[dependencies]

@ -0,0 +1,31 @@
use aoc::input;
fn main() {
let lines = input::read_lines();
let line = lines[0].to_owned();
// Part 1
let mut floor = 0;
for c in line.chars() {
match c {
'(' => floor += 1,
')' => floor -= 1,
_ => {}
}
}
println!("Floor: {}", floor);
// Part 2
floor = 0;
for (i, c) in line.chars().enumerate() {
match c {
'(' => floor += 1,
')' => floor -= 1,
_ => {}
}
if floor == -1 {
println!("Entered -1 at {}.", i + 1);
return
}
}
}

@ -0,0 +1,17 @@
use std::io;
pub fn read_lines() -> Vec<String> {
let mut lines = vec!();
loop {
let mut text = String::new();
let read_count = io::stdin().read_line(&mut text).unwrap();
if read_count == 0 {
break
}
if let Some(stripped) = text.strip_suffix("\n") {
text = stripped.to_string()
}
lines.push(text);
}
lines
}

@ -0,0 +1 @@
pub mod input;
Loading…
Cancel
Save