From 3a4c05ddc7b1b564510bfdd36283ad55ca9f599d Mon Sep 17 00:00:00 2001 From: June 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/src/bin') 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 79d99b372ac9bda2d9880833364ba0c769f8d29&follow=1'>diff
path: root/bin/1sh/show.c (unfollow)
Commit message (Collapse)Author
2020-08-18Highlight .in files as shJune McEnroe
Almost always templated shell for rc scripts.
2020-08-15Bump title buffer to 64KJune McEnroe
YouTube now sends <title> that occurs 38K into the file...
2020-08-09Publish "LibreTLS"June McEnroe
2020-08-02Add scooper update to "IRC Suite"June McEnroe
2020-07-31Add scooper to causal.agencyJune McEnroe
2020-07-25Fix setting second title request to GETJune McEnroe
Since 9c845be2797e2047547ec247cb037471aeb48bb0 in curl (7.71.0), setting CURLOPT_NOBODY to 1 sets the request method to HEAD, but setting it back to 0 does not change the method back to GET. Setting CURLOPT_HTTPGET both sets the request method and unsets CURLOPT_NOBODY.
2020-07-20Set pull.rebase trueJune McEnroe
2020-07-18Read from stdin in orderJune McEnroe
2020-07-18Actually fix nvim and doas presence testsJune McEnroe
2020-07-14Install up CGI with mode 700June McEnroe
It should never be served as a regular file.
2020-07-14Check that there is upload dataJune McEnroe
2020-07-14Add CGI upload program for temp.causal.agencyJune McEnroe
2020-07-10Add The Broken KingdomsJune McEnroe
2020-07-08Add facebook and twitter to title user-agentJune McEnroe
This fixes fetching tweets again! https://github.com/thelounge/thelounge/pull/ 3602 (Intentionally breaking the link so GitHub doesn't add a "referenced this PR" thing?)
2020-06-30Tweak causal.agency for mostly no reasonJune McEnroe
2020-06-30Add Ancillary JusticeJune McEnroe
2020-06-26Add password non-manager to planJune McEnroe
I've had this idea for years...
2020-06-26Tweak TF2 sensitivities once moreJune McEnroe
2020-06-19Add note about litterbox bot useJune McEnroe
2020-06-19Publish "IRC suite"June McEnroe
2020-06-17Add errors to link.shJune McEnroe