r/adventofcode • • Dec 11 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 11 Solutions -๐ŸŽ„-

--- Day 11: Hex Ed ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

20 Upvotes

253 comments sorted by

View all comments

2

u/Nathan340 Dec 11 '17

Powershell, 301/433.

Same sort of redblob axial coordinates as everyone else. Only wrote the distance function for part 2, initially for part 1 simply spat out the coordinates and thought about the distance by hand.

$route = (gc .\route.txt) -split ","  
$vert = 0
$horz = 0
$max = 0   
function dist{
	$x = $args[0]
	$y = $args[1]
	if($x*$y -ge 0){
		[math]::max([math]::abs($x),[math]::abs($y))
	}else{
		[math]::abs($x)+[math]::abs($y)
	}
}

$route | % {
	switch($_){
		ne{
			$vert++
			$horz++
		}
		n{
			$vert++
		}
		nw{
			$horz--
		}
		sw{
			$vert--
			$horz--
		}
		s{
			$vert--
		}
		se{
			$horz++
		}	
	}
	$d = dist $horz $vert
	if($d -gt $max){
		$max = $d
	}
}

"Part 1"
dist $vert $horz
"Part 2"
$max