summary refs log tree commit diff homepage
path: root/2017/src/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2017/src/bin/day02.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/2017/src/bin/day02.rs b/2017/src/bin/day02.rs
index 07551a2..ca721d7 100644
--- a/2017/src/bin/day02.rs
+++ b/2017/src/bin/day02.rs
@@ -11,14 +11,41 @@ fn solve1(input: &str) -> u32 {
     sum
 }
 
+fn solve2(input: &str) -> u32 {
+    let mut sum = 0;
+
+    for row in input.lines() {
+        let values: Vec<u32> = row.split_whitespace()
+            .map(str::parse)
+            .map(Result::unwrap)
+            .collect();
+
+        for x in &values {
+            for y in &values {
+                if x != y && x % y == 0 {
+                    sum += x / y;
+                }
+            }
+        }
+    }
+
+    sum
+}
+
 fn main() {
     let mut input = String::new();
     io::stdin().read_to_string(&mut input).unwrap();
 
     println!("Part 1: {}", solve1(&input));
+    println!("Part 2: {}", solve2(&input));
 }
 
 #[test]
 fn part1() {
     assert_eq!(18, solve1("5 1 9 5\n7 5 3\n2 4 6 8\n"));
 }
+
+#[test]
+fn part2() {
+    assert_eq!(9, solve2("5 9 2 8\n9 4 7 3\n3 8 6 5\n"));
+}
ventsJune McEnroe Still missing is logging MODE changes, which will be hell, unless it just logs the raw stuff. 2020-03-25Add logging functionsJune McEnroe The mkdir dance is a bit awkward... 2020-03-23Track MODE in repliesJune McEnroe 2020-03-23Fix non-multiline command newline handlingJune McEnroe 2020-03-23Add M-Enter to insert a newlineJune McEnroe 2020-03-23Handle bracketed paste, including newlinesJune McEnroe 2020-03-23Allow commands to take multiline inputJune McEnroe 2020-03-23Bump edit buffer cap to 1024June McEnroe With message splitting it's reasonable to allow this to be larger. 2020-03-23Assume worst case for unknown user and host in splitMessageJune McEnroe The default USERLEN of 9 doesn't have a great source, the RFC only says that nicks are length 9, so my assumption is that usernames are not longer. 2020-03-22Implement message splittingJune McEnroe 2020-03-22Handle empty input directly in commandJune McEnroe 2020-03-22Track own host, handle CHGHOSTJune McEnroe 2020-03-22Add /sayJune McEnroe 2020-03-22Handle RPL_CHANNELMODEISJune McEnroe 2020-03-22Handle user mode changesJune McEnroe 2020-03-22Rewrite handleModeJune McEnroe 2020-03-18Handle RPL_UMODEISJune McEnroe 2020-03-17Send blank line after 10 minutes idleJune McEnroe Without this, I was having catgirl "time out" from pounce's POV, but without catgirl noticing anything... I still don't understand this. Been using this fix for a couple weeks though and it stopped happening, and it's otherwise harmless, but yikes. 2020-03-09Ignore 422 ERR_NOMOTDJune McEnroe pounce will start sending these because some silly clients don't think they're connected until some MOTD reply... 2020-03-08Set self.pos before handling the messageJune McEnroe This intuitively feels wrong, but isn't. Most importantly, handleError immediately exits, but we still need to "consume" that message, otherwise pounce will keep sending it on reconnect. The same goes for any other handler that might cause an exit, such as a require parameter count failure. 2020-03-02Prevent entering commands in <debug> if restrictedJune McEnroe Because the <debug> ID always exists, it's possible to create a window for it even while restricted with "/window <debug>" and try to enter commands there. 2020-02-29Implement the causal.agency/consumer capabilityJune McEnroe 2020-02-25Add raw modes to mode messageJune McEnroe 2020-02-25Handle changing setParamModes, paramModes and other channel modesJune McEnroe 2020-02-25Fix handling EXCEPTS and INVEX without valuesJune McEnroe 2020-02-25Add /mode, /except, /invex and handle lists repliesJune McEnroe 2020-02-23Accumulate mode changes into a buffer for one messageJune McEnroe 2020-02-20Handle ERR_CHANOPRIVSNEEDEDJune McEnroe 2020-02-20Handle MODE changing channel list modesJune McEnroe 2020-02-20Handle MODE setting channel prefix modes