summary refs log tree commit diff homepage
path: root/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-12-03 23:52:16 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:13:50 -0500
commita38fe82e85802ba9f66da8064a56badcc30b7c96 (patch)
tree6356db526989913ce0b5ade68da9d6461b7ac663 /src/bin
parentDay 2 part 2 (diff)
downloadaoc-a38fe82e85802ba9f66da8064a56badcc30b7c96.tar.gz
aoc-a38fe82e85802ba9f66da8064a56badcc30b7c96.zip
Day 3
Diffstat (limited to '')
-rw-r--r--src/bin/day03.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/bin/day03.rs b/src/bin/day03.rs
new file mode 100644
index 0000000..8116acb
--- /dev/null
+++ b/src/bin/day03.rs
@@ -0,0 +1,43 @@
+use std::io::{self, Read};
+use std::str::FromStr;
+
+struct Triangle(u32, u32, u32);
+
+impl Triangle {
+    fn valid(&self) -> bool {
+        self.0 + self.1 > self.2
+            && self.1 + self.2 > self.0
+            && self.0 + self.2 > self.1
+    }
+}
+
+impl FromStr for Triangle {
+    type Err = ();
+    fn from_str(s: &str) -> Result<Self, ()> {
+        let mut iter = s.split_whitespace().map(str::parse);
+        match (iter.next(), iter.next(), iter.next()) {
+            (Some(Ok(a)), Some(Ok(b)), Some(Ok(c))) => Ok(Triangle(a, b, c)),
+            _ => Err(()),
+        }
+    }
+}
+
+fn solve(input: &str) -> usize {
+    input.lines()
+        .map(str::parse)
+        .map(Result::unwrap)
+        .filter(Triangle::valid)
+        .count()
+}
+
+fn main() {
+    let mut input = String::new();
+    io::stdin().read_to_string(&mut input).unwrap();
+
+    println!("Part 1: {}", solve(&input));
+}
+
+#[test]
+fn part1() {
+    assert_eq!(0, solve("5 10 25"));
+}
n title='2019-10-26 20:20:30 -0400'>2019-10-26Respond to PING with same parameterJune McEnroe 2019-10-26Add undocumented flag to disable verificationJune McEnroe 2019-10-26Do not require RPL_ISUPPORT for stateReadyJune McEnroe 2019-10-26Implement graceful shutdownJune McEnroe 2019-10-26Require PASS before USERJune McEnroe Prevent creating a ring consumer without authentication. 2019-10-26Track channel topicsJune McEnroe 2019-10-26Set AWAY when no clients are connectedJune McEnroe 2019-10-26Add flags to request TOPIC and NAMES on client connectJune McEnroe 2019-10-26OopsJune McEnroe 2019-10-26Disconnect client on unknown commandJune McEnroe During registration, no other commands should be sent. Afterwards, only intercepted commands will get parsed. 2019-10-26Allow reading sensitive information from filesJune McEnroe 2019-10-26Add rc scriptJune McEnroe 2019-10-25Add install and uninstall targetsJune McEnroe 2019-10-25Expand documentationJune McEnroe 2019-10-25Add AGPLv3 notice on client registrationJune McEnroe OwO 2019-10-25Rename project pounceJune McEnroeck check shows that almost all of the big/known IRC networks support TLS1.3 already; those who do not at least comply with SSL_CTX_set_cipher_list(3)'s "HIGH" set as can be tested like this: echo \ irc.hackint.org \ irc.tilde.chat \ irc.libera.chat \ irc.efnet.nl \ irc.oftc.net | xargs -tn1 \ openssl s_client -quiet -cipher HIGH -no_ign_eof -port 6697 -host 2021-07-08Use seprintf to build final 005June McEnroe Rather than causing a tls_write(3) for each remaining token. 2021-06-19Fix LDADD.crypt on DarwinJune McEnroe 2021-06-18Add -m mode option to set user modesJune McEnroe 2021-06-18Document channel keys in join optionJune McEnroe 2021-06-18Use | to separate flags from config optionsJune McEnroe This lets mandoc generate tags for the option names as well, so you can ":t away" in less(1), for example, and anchor links in HTML output. The added No's prevent the equals signs from being part of the anchor links. 2021-06-18Stop referring to server-time as IRCv3.2June McEnroe IRCv3 has moved away from grouping specs together into versions like this. SASL is still referred to as IRCv3.2 because there are two different versions of that spec. 2021-06-17Add mailing list archive to READMEJune McEnroe 2021-06-10Stop accumulating ISUPPORT tokens once MOTD startsJune McEnroe This avoids duplicating tokens when a client sends VERSION and the server responds with its 005s again. 2021-06-09Use seprintf for snip, removing strlcpynJune McEnroe 2021-06-09Use seprintf for reserializeJune McEnroe 2021-06-09Use seprintf for capListJune McEnroe 2021-06-09Add seprintfJune McEnroe Based on seprint(2) from Plan 9. I'm not sure if my return value exactly matches Plan 9's in the case of truncation. seprint(2) is described only as returning a pointer to the terminating '\0', but if it does so even in the case of truncation, it is awkward for the caller to detect. This implementation returns end in the truncation case, so that (ptr == end) indicates truncation. 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe Default MANDIR to ${PREFIX}/man since it turns out man-db includes /usr/local/man by default. Add support for BINDIR. Separate libs out into LDADD variables. 2021-04-30palaver: Exit on getopt failureJune McEnroe Oops. 2021-04-30notify: Implement pounce-notifyJune McEnroe