summary refs log tree commit diff homepage
path: root/src
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2016-12-20 20:58:39 -0500
committerJune McEnroe <programble@gmail.com>2016-12-20 20:58:39 -0500
commit0038403e3642a60579570611de2320e5fb9c2d93 (patch)
tree573f360fc02b07cd731bf8a7b0e4f39d26062bbf /src
parentDay 19 (diff)
downloadaoc-0038403e3642a60579570611de2320e5fb9c2d93.tar.gz
aoc-0038403e3642a60579570611de2320e5fb9c2d93.zip
Day 20
Diffstat (limited to 'src')
-rw-r--r--src/bin/day20.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/bin/day20.rs b/src/bin/day20.rs
new file mode 100644
index 0000000..3ed55af
--- /dev/null
+++ b/src/bin/day20.rs
@@ -0,0 +1,42 @@
+use std::io::{self, Read};
+
+fn solve(input: &str) -> u32 {
+    let mut ranges = vec![];
+
+    for line in input.lines() {
+        let hyphen = line.find('-').unwrap();
+        let (start, end) = line.split_at(hyphen);
+        let start: u32 = start.parse().unwrap();
+        let end: u32 = end[1..].parse().unwrap();
+        ranges.push((start, end));
+    }
+
+    ranges.sort();
+
+    let mut lowest = 0;
+
+    for &(start, end) in &ranges {
+        if lowest >= start && lowest <= end {
+            lowest = end + 1;
+        }
+    }
+
+    lowest
+}
+
+fn main() {
+    let mut input = String::new();
+    io::stdin().read_to_string(&mut input).unwrap();
+
+    println!("Part 1: {}", solve(&input));
+}
+
+#[test]
+fn part1() {
+    let input = "
+5-8
+0-2
+4-7
+";
+    assert_eq!(3, solve(input.trim()));
+}