From da5fe526ac4a7de3ab43a8045152b61e35c91c32 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 1 Dec 2017 00:55:04 -0500 Subject: Day 1, part 2 --- 2017/src/bin/day01.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to '2017/src/bin') 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")); } -- cgit 1.4.1 rch' size='10' name='q' value=''/>
path: root/man.sh (unfollow)
Commit message (Expand)Author
2022-03-12Fix r on empty bufferJune McEnroe
2022-03-12Implement $, 0, A, I, aJune McEnroe
2022-03-12Use a bool for vi.modeJune McEnroe
2022-03-12Implement r with countJune McEnroe
2022-03-12Implement vi R and rJune McEnroe
2022-03-12Treat C-v as an emacs keyJune McEnroe
2022-03-12Implement vi insert modeJune McEnroe
2022-03-12Lower ESCDELAY in vi modeJune McEnroe
2022-03-12Call editVi from input.cJune McEnroe
2022-03-12Add edit option to set line editing modeJune McEnroe
2022-03-12Reset to vi insert mode on enterJune McEnroe
2022-03-12Implement basic esc/i mode switchingJune McEnroe
2022-03-12Separate emacs key bindingsJune McEnroe
2022-03-09Always refresh the screen with ^LChristian Kellermann
2022-03-05Update STANDARDS section authors, titles and URLsJune McEnroe
2022-03-02Show own nick on /nick without paramsJune McEnroe
2022-02-26Specify commands which depend on capsJune McEnroe
2022-02-26Only add available commands to completeJune McEnroe
2022-02-26Factor out commandAvailableJune McEnroe
2022-02-23Give examples of "general events" 2.1June McEnroe
2022-02-23Add missing unistd.h include in input.cJune McEnroe
2022-02-22Document the interfaceJune McEnroe
2022-02-20Clean up unimplemented editing mode stuffJune McEnroe
2022-02-20Save input buffer contentsJune McEnroe
2022-02-20Share a cut buffer between all edit buffersJune McEnroe
2022-02-20Assert return values in edit testsJune McEnroe
2022-02-20Move mbs out of struct Edit, use a global bufferJune McEnroe
2022-02-20Clear edit buffer before running commandJune McEnroe
2022-02-20Show indicator in status when window has pending inputJune McEnroe
2022-02-20Use separate edit buffers for each IDJune McEnroe
2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe
2022-02-20Remove unused mbs.len field from struct EditJune McEnroe
2022-02-19Remove unneeded includes in ui.cJune McEnroe
2022-02-19Reimplement tab completeJune McEnroe
2022-02-19Handle errors from editFn, etc.June McEnroe
2022-02-19Reimplement text macrosJune McEnroe
2022-02-19Factor out input handling to input.cJune McEnroe
2022-02-19Factor out window management to window.cJune McEnroe
2022-02-19Enable -Wmissing-prototypesJune McEnroe
2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe
2022-02-19Run line editing testsJune McEnroe
2022-02-18Implement new line editing "library"June McEnroe
2022-02-18Simplify cursor positioning in inputJune McEnroe
2022-02-18Fix M-f orderingJune McEnroe
2022-02-12Move sandman build to scripts/MakefileJune McEnroe
2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe
2022-02-12Copy RPP defines from oconfigureJune McEnroe