summary refs log tree commit diff homepage
path: root/2017
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-12-15 13:53:00 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commit1704a21c695bac512261a4a187105ead4d4ad059 (patch)
tree8ac43f39e91f2d30674985108a93fc1c58042d7f /2017
parentDay 9, part 2 (diff)
downloadaoc-1704a21c695bac512261a4a187105ead4d4ad059.tar.gz
aoc-1704a21c695bac512261a4a187105ead4d4ad059.zip
Day 10
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"));
+}
71c&follow=1'>Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe I never use it. 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe My system is probably such a mess now... 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe Reading has really slowed down :( 2020-09-07Add SunglassesJune McEnroe An IRC find. 2020-09-06Add Between the BreathsJune McEnroe One of those good songs from a soundtrack of a film that probably isn't? The summary sounds a lot more interesting than the title implies, at least. 2020-09-04Open /dev/tty in nudgeJune McEnroe This makes it work even when it's run connected to a pipe, i.e. as the notify command of catgirl... 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe I guess this got lost somewhere, long ago... 2020-08-29Add tweets from retweetsJune McEnroe