From d45caa333b1b81dae4ffb395caba15ad4cc79003 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 3 Dec 2017 19:22:53 -0500 Subject: Day 3, clean up --- 2017/src/bin/day03.rs | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to '2017') diff --git a/2017/src/bin/day03.rs b/2017/src/bin/day03.rs index 4f38ac3..8a556a1 100644 --- a/2017/src/bin/day03.rs +++ b/2017/src/bin/day03.rs @@ -1,42 +1,20 @@ use std::io::{self, Read}; -// 17 16 15 14 13 -// 18 5 4 3 12 -// 19 6 1 2 11 -// 20 7 8 9 10 -// 21 22 23---> ... -// -// 1 R -// 1 U -// 2 L -// 2 D -// 3 R -// 3 U -// 4 L -// 4 D -// 5 R - fn solve1(input: i32) -> i32 { - let ds = [(1, 0), (0, 1), (-1, 0), (0, -1)]; - + let spiral = [(1, 0), (0, 1), (-1, 0), (0, -1)]; + let (mut x, mut y) = (0i32, 0i32); let mut n = 1; - let mut x = 0i32; - let mut y = 0i32; - let mut r = 1; - let mut i = 0; - for &(dx, dy) in ds.iter().cycle() { - for _ in 0..r { + for (i, &(dx, dy)) in spiral.iter().cycle().enumerate() { + let length = 1 + i / 2; + for _ in 0..length { if n == input { return x.abs() + y.abs(); } - n += 1; x += dx; y += dy; } - r += i % 2; - i += 1; } unreachable!() } -- cgit 1.4.1 id=b8056213935805d7dda21d41d7a515bdbab8667b&follow=1'>commit diff
path: root/www/git.causal.agency/cgit/README (unfollow)
Commit message (Collapse)Author
2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe
2021-01-11Publish "Using vi"June McEnroe
2021-01-11Enable diff.colorMovedJune McEnroe
2021-01-10Set less search case-insensitiveJune McEnroe
2021-01-10Set EXINITJune McEnroe
neovim is laggy as hell in my OpenBSD VM, so I switched to vi so I could type without getting frustrated.
2021-01-09Add c -t flag to print expression typeJune McEnroe
Also add missing float case.
2021-01-05Update taglineJune McEnroe