sln_2017_11
Copyright(c) Eric Mertens 2017
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2017/day/11

Day 11 asks us to implement a hex grid coordinate system and compute distances on it.

https://www.redblobgames.com/grids/hexagons/

  • X grid lines are diagonal from sw to ne
  • Y grid lines are vertical
  +  1,2 +
   \    /
0,2 +--+  2,1
   /    \
 -+  1,1 +-
   \    /
0,1 +--+  2,0
   /    \
  +  1,0 +
Synopsis

Documentation

data D Source #

Constructors

Dn 
Dne 
Dnw 
Dse 
Dsw 
Ds 

Instances

Instances details
Show D Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> D -> ShowS #

show :: D -> String #

showList :: [D] -> ShowS #

main :: IO () Source #

Print the solutions to day 11. The input file can be overridden via the command-line.

>>> :main
761
1542

distance :: Coord -> Int Source #

Compute minimum path distance from the origin on the hex grid.

>>> distance <$> [C (-1) 0,C (-1) 1,C 0 (-1),C 0 1,C 1 (-1),C 1 0]
[1,1,1,1,1,1]
>>> distance <$> [C (-1) (-1),C 1 1,C 2 (-1)]
[2,2,2]

translate :: D -> Coord Source #

Translate hex direction to grid projection.

>>> translate <$> [Dn,Ds,Dne,Dse,Dnw,Dsw]
[C (-1) 0,C 1 0,C (-1) 1,C 0 1,C 0 (-1),C 1 (-1)]