summary refs log tree commit diff homepage
path: root/2017/src/bin/day01.rs
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2017-12-01 00:55:04 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commit16a769b58bd9c47c35f80b92ab09d3bf36594aac (patch)
tree6733b218237b11669af42fc748218dda054f72ac /2017/src/bin/day01.rs
parentDay 1 (diff)
downloadaoc-16a769b58bd9c47c35f80b92ab09d3bf36594aac.tar.gz
aoc-16a769b58bd9c47c35f80b92ab09d3bf36594aac.zip
Day 1, part 2
Diffstat (limited to '')
-rw-r--r--2017/src/bin/day01.rs28
1 files changed, 21 insertions, 7 deletions
diff --git a/2017/src/bin/day01.rs b/2017/src/bin/day01.rs
index ee81d15..70ca5a6 100644
--- a/2017/src/bin/day01.rs
+++ b/2017/src/bin/day01.rs
@@ -1,10 +1,10 @@
 use std::io::{self, Read};
 
-fn solve(input: &str) -> u32 {
+fn solve(input: &str, skip: usize) -> u32 {
     let mut sum = 0;
 
     let chars = input.chars();
-    let nexts = input.chars().cycle().skip(1);
+    let nexts = input.chars().cycle().skip(skip);
 
     for (a, b) in chars.zip(nexts) {
         if a == b {
@@ -15,17 +15,31 @@ fn solve(input: &str) -> u32 {
     sum
 }
 
+fn solve2(input: &str) -> u32 {
+    solve(input, input.len() / 2)
+}
+
 fn main() {
     let mut input = String::new();
     io::stdin().read_to_string(&mut input).unwrap();
 
-    println!("Part 1: {}", solve(input.trim()));
+    println!("Part 1: {}", solve(input.trim(), 1));
+    println!("Part 2: {}", solve2(input.trim()));
 }
 
 #[test]
 fn part1() {
-    assert_eq!(3, solve("1122"));
-    assert_eq!(4, solve("1111"));
-    assert_eq!(0, solve("1234"));
-    assert_eq!(9, solve("91212129"));
+    assert_eq!(3, solve("1122", 1));
+    assert_eq!(4, solve("1111", 1));
+    assert_eq!(0, solve("1234", 1));
+    assert_eq!(9, solve("91212129", 1));
+}
+
+#[test]
+fn part2() {
+    assert_eq!(6, solve2("1212"));
+    assert_eq!(0, solve2("1221"));
+    assert_eq!(4, solve2("123425"));
+    assert_eq!(12, solve2("123123"));
+    assert_eq!(4, solve2("12131415"));
 }
class='logheader'>2021-06-20use uuids for avatar requests with webhooksdestruc7i0n 2021-06-09readme updatesdestruc7i0n regarding #72 and some feedback regarding Heroku 2021-06-06Missed an old 1.12 death message in the regexDaniel Matthies 2021-05-17Add config deprecation noticeDaniel Matthies 2021-04-21Fixing death message false positivesDaniel Matthies 2020-10-31update packagesdestruc7i0n 2020-10-29Add option to output server status into discordelveskevtar Signed-off-by: elveskevtar <kevtar@gmail.com> 2020-10-01new config stuffsurepy 2020-10-01Add compatibility options for minecraft versions lower than 1.7.2surepy 2020-08-04Update regex for replaceDiscordMentionsMarshall Oliver 2020-08-04Add nickname to variables objMarshall Oliver To use, add %nickname% to your MINCRAFT_TELLRAW_TEMPLATE var in config. 2020-07-22Fixed coding styleFeiko Joosten Fixed the coding style based on @destruc7i0n's feedback. 2020-07-17Changed tail to make use of watch file.Feiko Joosten Fixed an issue where the log file required a manual refresh before the new lines were detected. 2020-05-23Fixed user mention detectionZachery Notz 2020-05-23Improved regex so that TELLRAW templates can use variables more than onceZachery Notz 2020-04-29backwards compat with new optiondestruc7i0n 2020-04-29add the ability to handle webhook messagesdestruc7i0n 2020-04-19Fixed tellraw components not being encoded properlyBen Landin 2020-02-11Update README.mddestruc7i0n 2020-02-05Precedencedestruc7i0n 2020-02-05Allow specification of the channel name rather than iddestruc7i0n 2020-02-05Some more cleanupdestruc7i0n 2020-02-05More config handlingdestruc7i0n 2020-02-04Update typesdestruc7i0n 2020-02-04Docs updatesdestruc7i0n 2020-02-04Code cleanupdestruc7i0n 2020-02-04Refactor and rebuild to TypeScriptdestruc7i0n 2019-02-11Local file supportdestruc7i0n 2018-11-11Let's make this usable again!destruc7i0n 2018-02-23Allow configurable discord formatArcensoth 2018-02-23Revert example tellraw format to mimic the originalArcensoth 2018-02-23Update readme with new tellraw config optionArcensoth 2018-02-23Allow configurable tellraw formatArcensoth 2018-02-23Allow config file to be passed as a parameterArcensoth