day 20 sol1
This commit is contained in:
parent
e4e6730348
commit
e11b690d75
11 changed files with 1729 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
--
|
--
|
||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
--
|
--
|
||||||
-- hash: 877996d6cd90e6a9a1d5d7f01e79fd91225f46e4cf930943da73fad95dda8ea0
|
-- hash: dd5686d02b76a5cdfd0af22f3af753c80816616396b5f3c7ad773a552f9d0647
|
||||||
|
|
||||||
name: adventofcode
|
name: adventofcode
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
|
@ -48,7 +48,10 @@ library
|
||||||
Day16
|
Day16
|
||||||
Day17
|
Day17
|
||||||
Day18
|
Day18
|
||||||
|
Day19
|
||||||
other-modules:
|
other-modules:
|
||||||
|
Day20
|
||||||
|
DayXX
|
||||||
Permutations
|
Permutations
|
||||||
Paths_adventofcode
|
Paths_adventofcode
|
||||||
build-depends:
|
build-depends:
|
||||||
|
@ -56,6 +59,8 @@ library
|
||||||
, base >=4.7 && <5
|
, base >=4.7 && <5
|
||||||
, containers
|
, containers
|
||||||
, foldl
|
, foldl
|
||||||
|
, generic-lens
|
||||||
|
, lens
|
||||||
, parsec
|
, parsec
|
||||||
, protolude
|
, protolude
|
||||||
, text
|
, text
|
||||||
|
|
24
app/Main.hs
24
app/Main.hs
|
@ -26,6 +26,12 @@ import qualified Day15
|
||||||
import qualified Day16
|
import qualified Day16
|
||||||
import qualified Day17
|
import qualified Day17
|
||||||
import qualified Day18
|
import qualified Day18
|
||||||
|
import qualified Day19
|
||||||
|
-- import qualified Day20
|
||||||
|
-- import qualified Day21
|
||||||
|
-- import qualified Day22
|
||||||
|
-- import qualified Day23
|
||||||
|
-- import qualified Day24
|
||||||
|
|
||||||
showSol :: [Char] -> Doc -> IO ()
|
showSol :: [Char] -> Doc -> IO ()
|
||||||
showSol txt d = putText . toS . render $
|
showSol txt d = putText . toS . render $
|
||||||
|
@ -57,6 +63,12 @@ solutions = Map.fromList [(["01"], day01)
|
||||||
,(["16"], day16)
|
,(["16"], day16)
|
||||||
,(["17"], day17)
|
,(["17"], day17)
|
||||||
,(["18"], day18)
|
,(["18"], day18)
|
||||||
|
,(["19"], day19)
|
||||||
|
,(["20"], dayXX)
|
||||||
|
,(["21"], dayXX)
|
||||||
|
,(["22"], dayXX)
|
||||||
|
,(["23"], dayXX)
|
||||||
|
,(["24"], dayXX)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,3 +230,15 @@ day18 = do
|
||||||
showSol "Solution 1" (int (fromMaybe 0 sol1))
|
showSol "Solution 1" (int (fromMaybe 0 sol1))
|
||||||
let sol2 = Day18.solution2 input
|
let sol2 = Day18.solution2 input
|
||||||
showSol "Solution 2" (int sol2)
|
showSol "Solution 2" (int sol2)
|
||||||
|
|
||||||
|
day19 :: IO ()
|
||||||
|
day19 = do
|
||||||
|
putText "Day 19:"
|
||||||
|
input <- Day19.parseInput
|
||||||
|
let sol1 = Day19.solution1 input
|
||||||
|
showSol "Solution 1" (text sol1)
|
||||||
|
let sol2 = Day19.solution2 input
|
||||||
|
showSol "Solution 2" (int sol2)
|
||||||
|
|
||||||
|
dayXX :: IO ()
|
||||||
|
dayXX = putText "Not done yet"
|
||||||
|
|
201
inputs/day19.txt
Normal file
201
inputs/day19.txt
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
|
|
||||||
|
+-----------------------------------+ +-+ +-------------------------------------------------------------------------------------------+ +-+
|
||||||
|
| | | | | | | | |
|
||||||
|
+-----------------+ | +-----+ | +-----+ | | +---------------------------------------------|---+ |
|
||||||
|
| | | | | | | | | | |
|
||||||
|
+-------------+ +-+ | | | +---------------+ | | |
|
||||||
|
| | | | | | | | | | |
|
||||||
|
+---------------------------------------------------------------------|---------|-----------+ | | +---------------------|-----+
|
||||||
|
| | | | | | | | | | | | |
|
||||||
|
| | +-----+ +-------------------+ +-+ +-------------------------------------------------------------------------------------------+
|
||||||
|
| | | | | | | | | | | | |
|
||||||
|
| +-------|-------+ | +-|-+ +---|-------------------------------------------------------|---------------------------------------------|---+ |
|
||||||
|
| | | | | | | | | | | | | | |
|
||||||
|
| | | | | +-|-----|---------+ +-----------------------------------------------------------------|-------------------------|---+ |
|
||||||
|
| | | | | | | | | | | | | | | | |
|
||||||
|
| +-----------------------------|---|---|-----|---|-------------------------------------------+ | +-------------------|-------------------------+ +-+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---------------|-------------|-------|-------------|-----------|-----|-------------------------------------|-----------------------------------|---------------------------+ +-+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | +---|---+ +-----------+ +-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | +-------------|---------------------|-------|-----|-----------|-----|---------------------|---------------|---------------|-------+ | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---|-|---------------------------|---------------|---+ | | +---|-----|-----------------+ | | +---|-------------+ | | | | | +-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | +-------------------+ +-+ | +-----------------------------------+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | +---------------|-------------|---------------|-------|---------|-----|-+ | | | | | | | | | +-----------|-------------+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | P | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | +-|-------------------------|-|---------------|-|---------|-----------|-------|-------|-----------+ | +-------+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+-------------+ | | | +---------|---------------|-------|-|-----|-----------------|-|-|---+ | | | | | | | | | | +-----+ | +-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+-----+ | | | | | | | | +---------------|-----------------|-|-|-------------------------------------------|---|---|---------------------|-------+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +---------------|-------------|---------|-|-----|-------+ | | | | | | +---|-------------+ | | | | | | +-+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | +-------|---------------------|---|-+ +---+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------|---|-+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+---------------------|-------------|-----|-----|-|-------|-------|---------------|-|-----|-|-----|---------|---|---|-------------|-+ | | | | +---|---|-------------|-----+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---------+ | | | | | +---|-+ | | | | | | | | | | | | | | | | | +---------|---+ | +---|-+ | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-----------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | +-----------|-----|-----|-----|---|-|-----|---------------|-------|-|-----------------------|---------------------+ | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---|-|-----------|-----+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +---+ | | | | | | | +-----+ | | +-|-+ +-------------|-|---|-----------|-------|---|---+ | | | | | +-+ | | | +---------+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | +-|-|---|---|-|---------------------|-----|-|---------------------|-----------------|-----|---------+ | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | +---+ | | | | | | | | | | | | | | | | | | +-|-------------------|-----------|-+ | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------------|-------|-----------+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | +-----------|-----------------|---|-|-------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | +-------|-|-|---|-----------------|---------|---------------|-+ | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | +---|-------------|---|-|---|---------------|---|-|-----+ | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +---------------|-----------|-----|-+ | | | | | | | | | | | | +-|-----------|-------|---|-|-+ | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | +---|-------------------------+ | +-----|-----------|-------|-----------|-|-|-------|---------------|-+ | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | +-------------|---|-------------|-|---|-|---------+ | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +---------------|-------------|---|-----+ +-------|-------|-----|---------|-----------|---|-|-------------|-|-|-|-----|-------------|-|-|-|-----------|-----|-------+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | +---|-----|-----|-----------------+ | | | +---------|-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | +-+ | | | | | +-----+ | | | | | | | | | | | | | +-|-+ | +-+ | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | +-------|-------------------|-----------|---|------------Y--|-------------|---------------|-----|---|-----|---------|---|-----------+ | | | | | | |
|
||||||
|
| | | | X | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | +---------|---------------------------------------|-----|-----------|---|---------|-|-----------+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | +-|-------------------------|-----|-----------|-|-----------|---|-------------|---------|-|---|-|-----------|---------|-|---------------------|-|---------|-------|-----------|-+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | +-|---------|-------------|-|-|-------------|---------|-|-----------------|-------+ | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-----------|-----------------------|-|---+ | +---------------|-------------|---|-|-+ | | | | | | | +-------|---|-----|-|-+ | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | O | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | +-|-----|-----------------|-|---|-+ | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | +---------|-------|-|---|-----------------------|-|-|-|---+ | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | R | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | +-|---------|-|---------------|-------------|-+ | | | | | | | +-----|-|-|-|-|-------|-|-|-----------|-|-----|-|---+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | +---|-|---+ | +---------|-----------|-----------------|---------|-----------------------|-----|-+ | | | | +---------|---|---+ | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | +-----|---------|-|---------------|-------------|-----------|---|-----|-----------|---------|-|---+ +-+ +-----|-|---------------+ | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | W | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | +---|-----|-------|---|---+ | +-|-|---|-------|-|-------|-----|-+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | +-------+ | | | | | | | +-|---------------------|---|-|-|---|-+ | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------------|-|---|---|-|-------+ | | +-----+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | +-|-------|---------|-+ | +---+ | | | +-|-----|---------+ +-|-------------+ | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +-|-|-------|---------------|-------|-|-----------------|-------------|---|-----|-----------------|-|-|-|-----|-----------|-----|---|---|---|-|-----------|-----|-|-------------------------+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +-------+ | | | | +-+ +-------|---------|-------------|---|-----------------------|-----|-----|-------|---|-----|-----|---+ | | +---|-+ | | | | | | | | +-------+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | +-----|-------|---+ | | | | | +---+ | | | | | | +---|-|---|-------|---|-----|-|---|---------|-----------+ | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | +-|-------------|-----------|---------------+ +-|-----|-+ +---|-----|---|-|-------------|---|-+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +---------|-------------|-----------------------------------------------|-----|-------|---|-----|-----------|---|-------|-----|-|---|---+ | | | +-|-|---|---|---------------|-+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | +-----------------------|-|-|-----------------------|---|-|-----|-----------|-|-----------------------|-|-------+ | | | +-----|---|-|---|---+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | +---+ | | +-|-------------+ | | | | | | | +-----+ | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | E | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | +-----------+ | +-+ | | | | | | | | | | | | +-+ | | | | | | | | | | | +---|---|-+ |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | +-----------------------|---|-------|-----|-----------------------------------|-|---------------|-------|-----|---|---------|-|-----------+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|---------|---|---------------------|---|-------|-----------------------+ | | +-------------|---------+ | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | +-----------+ | +-----|-----|---+ | +-|-------|-|-----------------|-|---------|-------|-|-------------------|---|-------+ | +-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|---|---------|-|-|---------|-|-|-----|-----|-|-+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | +-----|-------------|-------------|-----------|-|-|---|---|---------|---|---------|---|-|-----+ | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | +-----------|-----|-----|---------+ | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | +-----------------------------------------------|-------|---|-----|-----------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | +-------------------------------------------------------|-|-------|---+ | | | +-|-----|-------------|-|---|-|---|---------------|-|---|---|-------------|-+ | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | +-|-----------|-----------|-----|---+ | | | | | | | +-----|-|-----------+ | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---|---------------------------------|---|-+ +---|---|-|-------|-|-----------|-|-|--H--------|---|-------------------|---|-|-----------------------+ | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | +-----|-|-|-------|-|---------|-|---------|---|---|-------|---|-------------|-----|-------------------|-----|---------|-|-------|-----|-----+ | | | +-|---+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------------+ | | | | +-+ | | | | +-|---|-|-------|---|-------|-|-+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | +---------------------|---|-|-----|-------------|-------------------------------|-|-------------|---------|---------------------------|---+ | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | +-----|-----|-------|---|-----------------|-|---|---|-|-----------------------------------|---------|---|-------|---+ | | | | | +-----+ | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | +-|---------------|-+ | | | +-------|---|-----------|-----------+ | | | +---------|-----|---|-------|-|-+ | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | +-------------|---|-------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | +---------|-|-|-------------------------|-----------------|---|-------|-|-------------|-|-----|---------|-----|---------|---|-------|-+ | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|-|-------|-------|-------------|-------|---+ | | | | +-----------+ | | | | | | | | | | | | | | | | | | | | | +-----+ | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | +-|-----------+ | | | | | | | | | | +-+ | | | | | | | +-|-------+ | | | +-------|---------------|---------|---+ | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | +-----------+ | | | | | | | | | +---|-------------|-----------|-------------|-----------|-|---|---------+ | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | +-|-----+ | | | | | | | | +---------------------|---|-|---|-|---|-------------|-----|---|-----|-------|-|-|---------------|---------------|-----------------|---+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | +-|-------|---|-----------|---------------+ | +---|-|-+ +-+ | | | +-------+ +-+ | | | | | | | +-------+ | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | +-|-|-----------------+ +---+ | | | | | +---|-|---|---------------------|-------|-------------------------------|---|-|-----|---|-------|-+ | | | +---|-----|-+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| | | | | | | | +-|-----|---------|-------------|-|-------------------------|-|-------------|-------------|---------|-----|-|---|---|-----+ | +-|-+ | | | +---+ | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|-|---|-|---------|-------------|---|-----------|---|-----------|-----------------+ | | | +-|---------+ | | | +-----|-----|-|---|-----------|---|-------|---|-|-----+ | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|-|-+ | | | | +-----|-|-------|---------------------------------|-------|-------+ +---------+ +---|-----|---|-|-|---+ | +---------+ | | | | | +-|---+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|-+ +-----|-------------------------|---|-------+ | | | | +---------|-----+ | | +---------------|---|-------|-------|---|-----------|-------------|-----|---+
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +---+ | +---------|---------------------|-----------------------|---|---------------|-----|-----------------+ | | +---------+ | | | | | | | | | | | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
| +-|-|-------|-------+ | | +-----------|---------|-|---|-----------------------|-----|-----------|---------|---|---------|---|-------------------|-------------|-----------+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+---+ | | | +-------------+ +-----------------------|-+ | | +---|---+ +-----------|-------|-----|-----------|-|-------+ +---|-------+ | +-----------+ | |
|
||||||
|
| | | | | | | | | | | | | | | | | | | | | | |
|
||||||
|
+---+ +-----------+ | | +---------------+ +-+ +-----------------+ | | +-----------|-------------------+ | | | | |
|
||||||
|
| | | | | | | | | | | | |
|
||||||
|
+-----------|-----------------------------------------------------------------|-|-------------|---|-----------------+ +---+ | | | |
|
||||||
|
| | | | | | | | | | | | |
|
||||||
|
+-----------+ +-------------------------------------------------------+ +---N +-+ +-----------------------+ +-------------+ +---+
|
||||||
|
|
1000
inputs/day20.txt
Normal file
1000
inputs/day20.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -31,6 +31,12 @@ library:
|
||||||
- Day16
|
- Day16
|
||||||
- Day17
|
- Day17
|
||||||
- Day18
|
- Day18
|
||||||
|
- Day19
|
||||||
|
# - Day20
|
||||||
|
# - Day21
|
||||||
|
# - Day22
|
||||||
|
# - Day23
|
||||||
|
# - Day24
|
||||||
dependencies:
|
dependencies:
|
||||||
- base >=4.7 && <5
|
- base >=4.7 && <5
|
||||||
- protolude
|
- protolude
|
||||||
|
@ -40,6 +46,8 @@ library:
|
||||||
- array
|
- array
|
||||||
- parsec
|
- parsec
|
||||||
- vector
|
- vector
|
||||||
|
- lens
|
||||||
|
- generic-lens
|
||||||
executables:
|
executables:
|
||||||
adventofcode-exe:
|
adventofcode-exe:
|
||||||
main: Main.hs
|
main: Main.hs
|
||||||
|
|
194
src/Day19.hs
Normal file
194
src/Day19.hs
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
{-|
|
||||||
|
|
||||||
|
Somehow, a network packet got lost and ended up here. It's trying to follow a
|
||||||
|
routing diagram (your puzzle input), but it's confused about where to go.
|
||||||
|
|
||||||
|
Its starting point is just off the top of the diagram. Lines (drawn with |, -,
|
||||||
|
and +) show the path it needs to take, starting by going down onto the only line
|
||||||
|
connected to the top of the diagram. It needs to follow this path until it
|
||||||
|
reaches the end (located somewhere within the diagram) and stop there.
|
||||||
|
|
||||||
|
Sometimes, the lines cross over each other; in these cases, it needs to continue
|
||||||
|
going the same direction, and only turn left or right when there's no other
|
||||||
|
option. In addition, someone has left letters on the line; these also don't
|
||||||
|
change its direction, but it can use them to keep track of where it's been. For
|
||||||
|
example:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
| +--+
|
||||||
|
A | C
|
||||||
|
F---|----E|--+
|
||||||
|
| | | D
|
||||||
|
+B-+ +--+
|
||||||
|
|
||||||
|
Given this diagram, the packet needs to take the following path:
|
||||||
|
|
||||||
|
- Starting at the only line touching the top of the diagram, it must go down,
|
||||||
|
pass through A, and continue onward to the first +.
|
||||||
|
- Travel right, up, and right, passing through B in the process.
|
||||||
|
- Continue down (collecting C), right, and up (collecting D).
|
||||||
|
- Finally, go all the way left through E and stopping at F.
|
||||||
|
|
||||||
|
Following the path to the end, the letters it sees on its path are ABCDEF.
|
||||||
|
|
||||||
|
The little packet looks up at you, hoping you can help it find the way. What
|
||||||
|
letters will it see (in the order it would see them) if it follows the path?
|
||||||
|
(The routing diagram is very wide; make sure you view it without line wrapping.)
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The packet is curious how many steps it needs to go.
|
||||||
|
|
||||||
|
For example, using the same routing diagram from the example above...
|
||||||
|
|
||||||
|
|
|
||||||
|
| +--+
|
||||||
|
A | C
|
||||||
|
F---|--|-E---+
|
||||||
|
| | | D
|
||||||
|
+B-+ +--+
|
||||||
|
|
||||||
|
...the packet would go:
|
||||||
|
|
||||||
|
- 6 steps down (including the first line at the top of the diagram).
|
||||||
|
- 3 steps right.
|
||||||
|
- 4 steps up.
|
||||||
|
- 3 steps right.
|
||||||
|
- 4 steps down.
|
||||||
|
- 3 steps right.
|
||||||
|
- 2 steps up.
|
||||||
|
- 13 steps left (including the F it stops on).
|
||||||
|
|
||||||
|
This would result in a total of 38 steps.
|
||||||
|
|
||||||
|
How many steps does the packet need to go?
|
||||||
|
|
||||||
|
|-}
|
||||||
|
|
||||||
|
module Day19 where
|
||||||
|
|
||||||
|
import Protolude
|
||||||
|
|
||||||
|
import Control.Lens hiding ((&))
|
||||||
|
import Data.Array
|
||||||
|
import Data.Generics.Product hiding (position)
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import GHC.Generics
|
||||||
|
|
||||||
|
type Grid = Array (Int,Int) Char
|
||||||
|
|
||||||
|
parseInput :: IO Grid
|
||||||
|
parseInput = parseTxt <$> readFile "inputs/day19.txt"
|
||||||
|
|
||||||
|
testInput :: Text
|
||||||
|
testInput = " | \n\
|
||||||
|
\ | +--+ \n\
|
||||||
|
\ A | C \n\
|
||||||
|
\ F---|----E|--+ \n\
|
||||||
|
\ | | | D \n\
|
||||||
|
\ +B-+ +--+ \n"
|
||||||
|
|
||||||
|
parseTxt :: Text -> Grid
|
||||||
|
parseTxt txt =
|
||||||
|
let
|
||||||
|
sentences :: [[Char]]
|
||||||
|
sentences = txt & T.lines & map T.unpack
|
||||||
|
bounds = ((1,1),(length sentences, maybe 0 length (head sentences)))
|
||||||
|
in listArray bounds (concat sentences)
|
||||||
|
|
||||||
|
data AppState =
|
||||||
|
AppState { letters :: [Char]
|
||||||
|
, position :: (Int,Int)
|
||||||
|
, direction :: (Int,Int)
|
||||||
|
, nbSteps :: Int
|
||||||
|
, grid :: Grid
|
||||||
|
} deriving (Eq, Show, Generic)
|
||||||
|
|
||||||
|
solution1 :: Grid -> [Char]
|
||||||
|
solution1 grid =
|
||||||
|
let finalState = execState runPath (AppState [] (1,1) (1,0) 0 grid)
|
||||||
|
in letters finalState & reverse
|
||||||
|
|
||||||
|
runPath :: State AppState ()
|
||||||
|
runPath = do
|
||||||
|
searchTop
|
||||||
|
followPath
|
||||||
|
|
||||||
|
searchTop :: State AppState ()
|
||||||
|
searchTop = do
|
||||||
|
grid <- use (field @"grid")
|
||||||
|
pos <- use (field @"position")
|
||||||
|
-- debugtr "searchTop"
|
||||||
|
when (grid ! pos /= '|') $ do
|
||||||
|
field @"position" . _2 += 1
|
||||||
|
searchTop
|
||||||
|
|
||||||
|
debugtr :: Text -> State AppState ()
|
||||||
|
debugtr str = do
|
||||||
|
grid <- use (field @"grid")
|
||||||
|
pos <- use (field @"position")
|
||||||
|
dir <- use (field @"direction")
|
||||||
|
ls <- use (field @"letters")
|
||||||
|
let res = (str,pos,grid ! pos,dir,reverse ls)
|
||||||
|
traceShow (deepseq res res) return ()
|
||||||
|
|
||||||
|
followPath :: State AppState ()
|
||||||
|
followPath = do
|
||||||
|
grid <- use (field @"grid")
|
||||||
|
pos <- use (field @"position")
|
||||||
|
-- debugtr "followPath"
|
||||||
|
case grid ! pos of
|
||||||
|
'+' -> searchNewDirection
|
||||||
|
' ' -> continue
|
||||||
|
'|' -> continue
|
||||||
|
'-' -> continue
|
||||||
|
c -> do
|
||||||
|
field @"letters" %= (c:)
|
||||||
|
searchNewDirection
|
||||||
|
|
||||||
|
addDir :: (Int,Int) -> (Int,Int) -> (Int,Int)
|
||||||
|
addDir (x1,y1) (x2,y2) = (x1+x2,y1+y2)
|
||||||
|
|
||||||
|
continue :: State AppState ()
|
||||||
|
continue = do
|
||||||
|
dir <- use (field @"direction")
|
||||||
|
field @"position" %= addDir dir
|
||||||
|
field @"nbSteps" += 1
|
||||||
|
-- debugtr "continue"
|
||||||
|
followPath
|
||||||
|
|
||||||
|
inBound :: ((Int,Int),(Int,Int)) -> (Int,Int) -> Bool
|
||||||
|
inBound ((minx,miny),(maxx,maxy)) (x,y) =
|
||||||
|
minx <= x && x <= maxx && miny <= y && y <= maxy
|
||||||
|
|
||||||
|
backdir :: (Int,Int) -> (Int,Int)
|
||||||
|
backdir (x,y) = (-x,-y)
|
||||||
|
|
||||||
|
searchNewDirection :: State AppState ()
|
||||||
|
searchNewDirection = do
|
||||||
|
grid <- use (field @"grid")
|
||||||
|
(posx,posy) <- use (field @"position")
|
||||||
|
dir <- use (field @"direction")
|
||||||
|
let
|
||||||
|
bnds = bounds grid
|
||||||
|
possibleDirs = [(1,0), (0,-1), (-1,0), (0,1)]
|
||||||
|
& filter (/= backdir dir)
|
||||||
|
& map (\(dx,dy)->((dx,dy),(posx+dx,posy+dy)))
|
||||||
|
& filter (\(_,p)-> inBound bnds p && grid ! p /= ' ')
|
||||||
|
-- traceShow possibleDirs $ return ()
|
||||||
|
case possibleDirs of
|
||||||
|
[(newdir,_)] -> do
|
||||||
|
field @"direction" .= newdir
|
||||||
|
continue
|
||||||
|
_ -> return ()
|
||||||
|
|
||||||
|
solution2 :: Grid -> Int
|
||||||
|
solution2 grid =
|
||||||
|
let finalState = execState runPath (AppState [] (1,1) (1,0) 0 grid)
|
||||||
|
in 1 + nbSteps finalState
|
152
src/Day20.hs
Normal file
152
src/Day20.hs
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
{-|
|
||||||
|
|
||||||
|
--- Day 20: Particle Swarm ---
|
||||||
|
|
||||||
|
Suddenly, the GPU contacts you, asking for help. Someone has asked it to
|
||||||
|
simulate too many particles, and it won't be able to finish them all in time to
|
||||||
|
render the next frame at this rate.
|
||||||
|
|
||||||
|
It transmits to you a buffer (your puzzle input) listing each particle in order
|
||||||
|
(starting with particle 0, then particle 1, particle 2, and so on). For each
|
||||||
|
particle, it provides the X, Y, and Z coordinates for the particle's position
|
||||||
|
(p), velocity (v), and acceleration (a), each in the format <X,Y,Z>.
|
||||||
|
|
||||||
|
Each tick, all particles are updated simultaneously. A particle's properties are
|
||||||
|
updated in the following order:
|
||||||
|
|
||||||
|
Increase the X velocity by the X acceleration.
|
||||||
|
Increase the Y velocity by the Y acceleration.
|
||||||
|
Increase the Z velocity by the Z acceleration.
|
||||||
|
Increase the X position by the X velocity.
|
||||||
|
Increase the Y position by the Y velocity.
|
||||||
|
Increase the Z position by the Z velocity.
|
||||||
|
|
||||||
|
Because of seemingly tenuous rationale involving z-buffering, the GPU would like
|
||||||
|
to know which particle will stay closest to position <0,0,0> in the long term.
|
||||||
|
Measure this using the Manhattan distance, which in this situation is simply the
|
||||||
|
sum of the absolute values of a particle's X, Y, and Z position.
|
||||||
|
|
||||||
|
For example, suppose you are only given two particles, both of which stay
|
||||||
|
entirely on the X-axis (for simplicity). Drawing the current states of particles
|
||||||
|
0 and 1 (in that order) with an adjacent a number line and diagram of current X
|
||||||
|
positions (marked in parenthesis), the following would take place:
|
||||||
|
|
||||||
|
p=< 3,0,0>, v=< 2,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
|
||||||
|
p=< 4,0,0>, v=< 0,0,0>, a=<-2,0,0> (0)(1)
|
||||||
|
|
||||||
|
p=< 4,0,0>, v=< 1,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
|
||||||
|
p=< 2,0,0>, v=<-2,0,0>, a=<-2,0,0> (1) (0)
|
||||||
|
|
||||||
|
p=< 4,0,0>, v=< 0,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
|
||||||
|
p=<-2,0,0>, v=<-4,0,0>, a=<-2,0,0> (1) (0)
|
||||||
|
|
||||||
|
p=< 3,0,0>, v=<-1,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
|
||||||
|
p=<-8,0,0>, v=<-6,0,0>, a=<-2,0,0> (0)
|
||||||
|
|
||||||
|
At this point, particle 1 will never be closer to <0,0,0> than particle 0, and
|
||||||
|
so, in the long run, particle 0 will stay closest.
|
||||||
|
|
||||||
|
|-}
|
||||||
|
|
||||||
|
module Day20 where
|
||||||
|
|
||||||
|
import Protolude
|
||||||
|
|
||||||
|
import Control.Lens hiding ((&))
|
||||||
|
-- import Data.Array
|
||||||
|
import Data.Generics.Product
|
||||||
|
-- import qualified Data.Text as T
|
||||||
|
import GHC.Generics
|
||||||
|
import Text.Parsec hiding (State)
|
||||||
|
|
||||||
|
type Input = [Particle]
|
||||||
|
data Particle = Particle { pos :: Coord
|
||||||
|
, vit :: Coord
|
||||||
|
, acc :: Coord
|
||||||
|
} deriving (Show,Eq,Generic)
|
||||||
|
|
||||||
|
data Coord = Coord { x,y,z :: Int } deriving (Show,Eq,Generic)
|
||||||
|
instance Num Coord where
|
||||||
|
negate (Coord x y z) = Coord (negate x) (negate y) (negate z)
|
||||||
|
(Coord x1 y1 z1) + (Coord x2 y2 z2) = Coord (x1 + x2) (y1 + y2) (z1 + z2)
|
||||||
|
(Coord x1 y1 z1) * (Coord x2 y2 z2) = Coord (x1 * x2) (y1 * y2) (z1 * z2)
|
||||||
|
fromInteger x = Coord (fromInteger x) 0 0
|
||||||
|
abs (Coord x y z) = Coord (abs x) (abs y) (abs z)
|
||||||
|
signum (Coord x y z) = Coord (signum x) (signum y) (signum z)
|
||||||
|
|
||||||
|
instance Monoid Coord where
|
||||||
|
mempty = Coord 0 0 0
|
||||||
|
|
||||||
|
dist :: Coord -> Coord -> Int
|
||||||
|
dist c1 c2 = let dv = abs (c1 - c2) in (x dv) + (y dv) + (z dv)
|
||||||
|
|
||||||
|
parseInput :: IO Input
|
||||||
|
parseInput = parseText <$> readFile "inputs/day20.txt"
|
||||||
|
|
||||||
|
testInput :: Text
|
||||||
|
testInput = "p=<3,0,0>, v=<2,0,0>, a=<-1,0,0>\n\
|
||||||
|
\p=<4,0,0>, v=<0,0,0>, a=<-2,0,0>\n"
|
||||||
|
|
||||||
|
parseText :: Text -> Input
|
||||||
|
parseText txt = either (const []) identity (runParser mainParse () "Input" txt)
|
||||||
|
|
||||||
|
mainParse :: Parsec Text () Input
|
||||||
|
mainParse = many1 parseParticle
|
||||||
|
|
||||||
|
parseParticle :: Parsec Text () Particle
|
||||||
|
parseParticle = Particle <$> (string "p=" *> parseCoord)
|
||||||
|
<*> (string ", v=" *> parseCoord)
|
||||||
|
<*> (string ", a=" *> parseCoord <* newline)
|
||||||
|
|
||||||
|
parseCoord :: Parsec Text () Coord
|
||||||
|
parseCoord = Coord <$> (char '<' *> parseInt)
|
||||||
|
<*> (char ',' *> parseInt)
|
||||||
|
<*> (char ',' *> parseInt <* char '>')
|
||||||
|
|
||||||
|
parseInt :: Parsec Text () Int
|
||||||
|
parseInt = do
|
||||||
|
sgn <- optionMaybe (char '-')
|
||||||
|
str <- many1 digit
|
||||||
|
let strint = case sgn of
|
||||||
|
Nothing -> str
|
||||||
|
Just _ -> "-" <> str
|
||||||
|
return $ fromMaybe 0 (reads strint & head & fmap fst)
|
||||||
|
|
||||||
|
-- Solution 1
|
||||||
|
|
||||||
|
type Solution1 = Int
|
||||||
|
|
||||||
|
data AppState = AppState { particles :: [Particle] } deriving (Show,Eq,Generic)
|
||||||
|
|
||||||
|
solution1 :: Input -> Solution1
|
||||||
|
solution1 input =
|
||||||
|
input
|
||||||
|
& zip ([0..] :: [Int])
|
||||||
|
& map (\(i,p) -> (i,d (pos p), d (vit p), d (acc p)))
|
||||||
|
& sortOn (\(_,x,_,_)->x)
|
||||||
|
& sortOn (\(_,_,x,_)->x)
|
||||||
|
& sortOn (\(_,_,_,x)->x)
|
||||||
|
& head
|
||||||
|
& fmap (^._1)
|
||||||
|
& fromMaybe 0
|
||||||
|
where
|
||||||
|
d = dist mempty
|
||||||
|
|
||||||
|
-- Solution 2
|
||||||
|
|
||||||
|
type Solution2 = Int
|
||||||
|
|
||||||
|
solution2 :: Input -> Solution2
|
||||||
|
solution2 grid =
|
||||||
|
let initState = undefined
|
||||||
|
in extractSol $ execState solve2 initState
|
||||||
|
where
|
||||||
|
extractSol :: AppState -> Solution2
|
||||||
|
extractSol = undefined
|
||||||
|
solve2 :: State AppState ()
|
||||||
|
solve2 = undefined
|
58
src/DayXX.hs
Normal file
58
src/DayXX.hs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
{-|
|
||||||
|
|-}
|
||||||
|
|
||||||
|
module DayXX where
|
||||||
|
|
||||||
|
import Protolude
|
||||||
|
|
||||||
|
-- import Control.Lens hiding ((&))
|
||||||
|
-- import Data.Array
|
||||||
|
-- import Data.Generics.Product
|
||||||
|
-- import qualified Data.Text as T
|
||||||
|
import GHC.Generics
|
||||||
|
|
||||||
|
type Input = [Text]
|
||||||
|
|
||||||
|
parseInput :: IO Input
|
||||||
|
parseInput = parseText <$> readFile "inputs/day19.txt"
|
||||||
|
|
||||||
|
testInput :: Text
|
||||||
|
testInput = ""
|
||||||
|
|
||||||
|
parseText :: Text -> Input
|
||||||
|
parseText = undefined
|
||||||
|
|
||||||
|
-- Solution 1
|
||||||
|
|
||||||
|
type Solution1 = Int
|
||||||
|
|
||||||
|
data AppState = AppState () deriving (Show,Eq,Generic)
|
||||||
|
|
||||||
|
solution1 :: Input -> Solution1
|
||||||
|
solution1 grid =
|
||||||
|
let initState = AppState ()
|
||||||
|
in extractSol $ execState solve1 initState
|
||||||
|
where
|
||||||
|
extractSol :: AppState -> Solution1
|
||||||
|
extractSol = undefined
|
||||||
|
solve1 :: State AppState ()
|
||||||
|
solve1 = undefined
|
||||||
|
|
||||||
|
-- Solution 2
|
||||||
|
|
||||||
|
type Solution2 = Int
|
||||||
|
|
||||||
|
solution2 :: Input -> Solution2
|
||||||
|
solution2 grid =
|
||||||
|
let initState = AppState ()
|
||||||
|
in extractSol $ execState solve2 initState
|
||||||
|
where
|
||||||
|
extractSol :: AppState -> Solution2
|
||||||
|
extractSol = undefined
|
||||||
|
solve2 :: State AppState ()
|
||||||
|
solve2 = undefined
|
|
@ -49,3 +49,23 @@ rotate n (Permutation p) =
|
||||||
instance (Ix i,Enum i) => Semigroup (Permutation i) where
|
instance (Ix i,Enum i) => Semigroup (Permutation i) where
|
||||||
Permutation a1 <> Permutation a2 = Permutation $
|
Permutation a1 <> Permutation a2 = Permutation $
|
||||||
array (bounds a2) [ (i, a2 ! j) | (i,j) <- assocs a1]
|
array (bounds a2) [ (i, a2 ! j) | (i,j) <- assocs a1]
|
||||||
|
|
||||||
|
{-
|
||||||
|
|
||||||
|
0 1 2 === 0
|
||||||
|
1 0 2 => p1
|
||||||
|
0 2 1 => p2
|
||||||
|
2 1 0 => p3
|
||||||
|
1 2 0 => p4
|
||||||
|
|
||||||
|
p1 <> p2 ===> 2 0 1
|
||||||
|
p2 <> p1 ===> 1 2 0
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
testPermutation =
|
||||||
|
let p0 = nullPerm (0,2)
|
||||||
|
p1 = swap 0 1 p0
|
||||||
|
p2 = swap 1 2 p0
|
||||||
|
p3 = p1 <> p2
|
||||||
|
in p2 <> p1
|
||||||
|
|
|
@ -39,7 +39,8 @@ packages:
|
||||||
- .
|
- .
|
||||||
# Dependency packages to be pulled from upstream that are not in the resolver
|
# Dependency packages to be pulled from upstream that are not in the resolver
|
||||||
# (e.g., acme-missiles-0.3)
|
# (e.g., acme-missiles-0.3)
|
||||||
extra-deps: []
|
extra-deps:
|
||||||
|
- generic-lens-0.5.0.0
|
||||||
|
|
||||||
# Override default flag values for local packages and extra-deps
|
# Override default flag values for local packages and extra-deps
|
||||||
flags: {}
|
flags: {}
|
||||||
|
|
63
test/Spec.hs
63
test/Spec.hs
|
@ -20,6 +20,15 @@ import qualified Day12
|
||||||
import qualified Day13
|
import qualified Day13
|
||||||
import qualified Day14
|
import qualified Day14
|
||||||
import qualified Day15
|
import qualified Day15
|
||||||
|
import qualified Day16
|
||||||
|
import qualified Day17
|
||||||
|
import qualified Day18
|
||||||
|
import qualified Day19
|
||||||
|
-- import qualified Day20
|
||||||
|
-- import qualified Day21
|
||||||
|
-- import qualified Day22
|
||||||
|
-- import qualified Day23
|
||||||
|
-- import qualified Day24
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = defaultMain $
|
main = defaultMain $
|
||||||
|
@ -273,3 +282,57 @@ testDay15 =
|
||||||
Day15.solution2 Day15.testInput @?= 309
|
Day15.solution2 Day15.testInput @?= 309
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
testDay16 =
|
||||||
|
testGroup "Day 16"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay17 =
|
||||||
|
testGroup "Day 17"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay18 =
|
||||||
|
testGroup "Day 18"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay19 =
|
||||||
|
testGroup "Day 19"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay20 =
|
||||||
|
testGroup "Day 20"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay21 =
|
||||||
|
testGroup "Day 21"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay22 =
|
||||||
|
testGroup "Day 22"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay23 =
|
||||||
|
testGroup "Day 23"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
||||||
|
testDay24 =
|
||||||
|
testGroup "Day 24"
|
||||||
|
[ testGroup "Solution 1" []
|
||||||
|
, testGroup "Solution 2" []
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in a new issue