summary refs log tree commit diff homepage
path: root/2017
diff options
context:
space:
mode:
Diffstat (limited to '2017')
-rw-r--r--2017/input/day10.txt1
-rw-r--r--2017/src/bin/day10.rs38
2 files changed, 39 insertions, 0 deletions
diff --git a/2017/input/day10.txt b/2017/input/day10.txt
new file mode 100644
index 0000000..bae3d9a
--- /dev/null
+++ b/2017/input/day10.txt
@@ -0,0 +1 @@
+70,66,255,2,48,0,54,48,80,141,244,254,160,108,1,41
\ No newline at end of file
diff --git a/2017/src/bin/day10.rs b/2017/src/bin/day10.rs
new file mode 100644
index 0000000..af90961
--- /dev/null
+++ b/2017/src/bin/day10.rs
@@ -0,0 +1,38 @@
+use std::io::{self, Read};
+
+fn reverse(ring: &mut Vec<u32>, index: usize, len: usize) {
+    for i in 0..(len / 2) {
+        let a = (index + i) % ring.len();
+        let b = (index + len - 1 - i) % ring.len();
+        let x = ring[a];
+        ring[a] = ring[b];
+        ring[b] = x;
+    }
+}
+
+fn solve1(size: u32, input: &str) -> u32 {
+    let mut ring: Vec<_> = (0..size).collect();
+    let mut index = 0;
+    let mut skip = 0;
+
+    for len in input.split(',').map(str::parse).map(Result::unwrap) {
+        reverse(&mut ring, index, len);
+        index += len + skip;
+        index %= ring.len();
+        skip += 1;
+    }
+
+    ring[0] * ring[1]
+}
+
+fn main() {
+    let mut input = String::new();
+    io::stdin().read_to_string(&mut input).unwrap();
+
+    println!("Part 1: {}", solve1(256, input.trim()));
+}
+
+#[test]
+fn part1() {
+    assert_eq!(12, solve1(5, "3,4,1,5"));
+}
Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe 2022-07-03Add The Bone Shard EmperorJune McEnroe 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe