summary refs log tree commit diff homepage
path: root/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2016-12-20 20:58:39 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commitde858ad36f2232dc5ec6088d2bb47c1235c56277 (patch)
tree082c014b282660727ff97aba689883a673ca9e3e /src/bin
parentDay 19 (diff)
downloadaoc-de858ad36f2232dc5ec6088d2bb47c1235c56277.tar.gz
aoc-de858ad36f2232dc5ec6088d2bb47c1235c56277.zip
Day 20
Diffstat (limited to 'src/bin')
-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()));
+}
t/scoop.1?h=1.8&id=2a2ea06fbcbbcbaf2dfb77027b47dc57f8897994&follow=1'>Document ENVIRONMENT in scoop(1)June McEnroe 2019-12-31Add before and after optionsJune McEnroe 2019-12-31Add scoop IRC output formatJune McEnroe 2019-12-31Add scoop output format optionJune McEnroe 2019-12-31Refactor scoop formatters and group colored outputJune McEnroe 2019-12-31Add strftime format string optionJune McEnroe 2019-12-31Refactor binding in scoopJune McEnroe 2019-12-31Add option to group events by contextJune McEnroe 2019-12-31Add missing includeJune McEnroe 2019-12-31Use standout mode for highlightingJune McEnroe 2019-12-31Rewrite scoop(1) argument descriptionsJune McEnroe 2019-12-31Color both nicks in a changeJune McEnroe 2019-12-31Implement nick-colored outputJune McEnroe 2019-12-31Only enable highlighting on terminal outputJune McEnroe 2019-12-31Set up pager pipeJune McEnroe 2019-12-30Normalize date inputJune McEnroe Mostly this just allows the use of 'now'. 2019-12-30Add initial rough version of scoopJune McEnroe 2019-12-30Join with USING wherever possibleJune McEnroe 2019-12-30Add -D flag to prospective scoop manualJune McEnroe 2019-12-30Order results by ID in outer query in litterboxJune McEnroe 2019-12-30Use X macro for Type enumJune McEnroe 2019-12-30Remove scoop -ABCJune McEnroe I can almost get these to work with an inner and outer SQL query, but when contexts starts overlapping it becomes a disaster, so I'm leavin it out at least for now. 2019-12-30Add limit option for litterbox's search query interfaceJune McEnroe