Day 19
authorNeil Smith <neil.git@njae.me.uk>
Tue, 19 Dec 2017 09:52:41 +0000 (09:52 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 19 Dec 2017 09:52:41 +0000 (09:52 +0000)
advent-of-code.cabal
data/advent19.txt [new file with mode: 0644]
problems/day19.html [new file with mode: 0644]
src/advent19/advent19.hs [new file with mode: 0644]
src/advent19/advent19.ipynb [new file with mode: 0644]
src/advent19/sample-maze.txt [new file with mode: 0644]

index 05e1ef7d0bae9b1fad62c5df3d39842c67b56fa2..fbfac7d3eb7b5e06c3814e3e75ab055772faaa0c 100644 (file)
@@ -202,4 +202,10 @@ executable advent18b
                      , containers
                      , mtl
                      , text
-                     , megaparsec
\ No newline at end of file
+                     , megaparsec
+
+executable advent19
+  hs-source-dirs:      src/advent19
+  main-is:             advent19.hs
+  default-language:    Haskell2010
+  build-depends:       base >= 4.7 && < 5
diff --git a/data/advent19.txt b/data/advent19.txt
new file mode 100644 (file)
index 0000000..21ac1a5
--- /dev/null
@@ -0,0 +1,201 @@
+                                                                             |                                                                                                                           
+             +-------+       +-------+   +-+                                 | +-------------------------------------------+                   +---------------+     +-+ +---------------------------+   
+             |       |       |       |   | |                                 | |                                           |                   |               |     | | |                           |   
+ +---------------------------+       |   | +---------------------------------|-|---------+   +-----------------------------------------------------------------|-----|-|-----+                       |   
+ |           |       |               |   |                                   | |         |   |                             |                   |               |     | | |   |                       |   
+ |           +-----------------------|---------------------------------------|-|---------|---|-----------------+           |                   |               | +---|-+ +-------------------------+ |   
+ |                   |               |   |                                   | |         |   |                 |           |                   |               | |   |       |                     | |   
+ |                   |         +-----|-+ |                 +-----------------|-+ +-------|---|-+               +---------------------------------------+       | |   | +-+   |     +-----+ +-+   +-|-|-+ 
+ |                   |         |     | | |                 |                 |   |       |   | |                           |                   |       |       | |   | | |   |     |     | | |   | | | | 
+ |           +---------------------------------------------+                 |   +-----------|-|-----------+               |                   |       |       | |   | | |   |     |     | | |   | | | | 
+ |           |       |         |     | | |                                   |           |   | |           |               |                   |       |       | |   | | |   |     |     | | |   | | | | 
+ |           | +-----|---------|-----|-|---------------+                     |           |   | |         +-|---------------|-----------+       |       |       | |   | | |   |   +-+     | | |   | | | | 
+ |           | |     |         |     | | |             |                     |           |   | |         | |               |           |       |       |       | |   | | |   |   |       | | |   | | | | 
+ |           | |     |         |     | | |             |                     |           | +----Q----------+               |           |       |       |       | |   | | |   |   |     +-|---+   | | | | 
+ |           | |     |         |     | | |             |                     |           | | | |         |                 |           |       |       |       | |   | | |   |   |     | | |     | | | | 
+ |           | |     |         |     | | |             | +---------------------------+   +-|---|---------|-------------------------------+     |     +---------|-|-----------|---|-----|---------|-+ | | 
+ |           | |     |         |     | | |             | |                   |       |     | | |         |                 |           | |     |     | |       | |   | | |   |   |     | | |     |   | | 
+ +-+ +-+     | |   +-----+     |     | +-|---------+   | |                   |       |     | | +-+       |                 |   +-------|-------------|-|---------|---|-|-----|---|-----|---|-----+   | | 
+   | | |     | |   | |   |     |     |   |         |   | |                   |       |     | |   |       |                 |   |       | |     |     | |       | |   | | |   |   |     | | |         | | 
+ +-----|-+   | |   | |   +-----|-------------+     |   | |                   |       |     | |   |       |       +-----+   |   |   +---|-------|-----|-|-----+ | | +-|-|-|-+ | +-|---+ | | |         | | 
+ | | | | |   | |   | |         |     |   |   |     |   | |                   |       |     | |   |       |       |     |   |   |   |   | |     |     | |     | | | | | | | | | | |   | | | |         | | 
+ | | | | |   | |   | |         |     |   |   |     |   | |         +-----------------------------|-------|-------------|---------------|-------|-----+ |     +---|-|-|-|-----|-|---+ | | | |         | | 
+ | | | | |   | |   | |         |     |   |   |     |   | |         |         |       |     | |   |       |       |     |   |   |   |   | |     |       |       | | | | | | | | | | | | | | |         | | 
+ | +-----|-----|---------------|-----|---|---|---------|-|-------------------|-------------|-|---------+ |       +-------------|---|---|-------|-------|-------+ | | +---|-----|-|-------|-|-------+ | | 
+ |   | | |   | |   | |         |     |   |   |     |   | |         |         |       |     | |   |     | |             |   |   |   |   | |     |       |         | |   | | | | | | | | | | |       | | | 
+ +-------|---|-|---+ |         +-+   |   +---------|---|-|---------|---------|---------------|---|-----|---------------------------|---|-------|-------|-------------+ | | | | | | | | | | |       | | | 
+     | | |   | |     |           |   |       |     |   | |         |         |       |     | |   |     | |             |   |   |   |   | |     |       |         | | | | | | | | | | | | | |       | | | 
+   +-|---------|-----|-------+   |   |       |     |   | |   +---------------|-------------|-----|-------|-------------|---|-----------|-|-----|---------------------|-|-|-------------|-+ |       | | | 
+   | | | |   | |     |       |   |   |       |     |   | |   |     |         |       |     | |   |     | |             |   |   |   |   | |     |       |         | | | | | | | | | | | |   |       | | | 
+ +-+ | +-|---------+ |       |   |   |       |     |   | |   |     |         | +-----------|-----------|-|-+     +---------|---|---|---|-|---------------------------------|-|---|---|---+ |       | | | 
+ |   |   |   | |   | |       |   |   |       |     |   | |   |     |         | |     |     | |   |     | | |     |     |   |   |   |   | |     |       |         | | | | | | | | | | | | | |       | | | 
+ |   +-------------|-|-----------|-----------------|-----|---------|-----------|-------------|---|-----|-+ |     |     |   |   |   |   +-|-------------|---------------------|-|-+ | | | | |       | | | 
+ |       |   | |   | |       |   |   |       |     |   | |   |     |         | |     |     | |   |     |   |     |     |   |   |   |     |     |       |         | | | | | | | |   | | | | |       | | | 
+ +-------+   | |   | |       |   |   |       |     +---|---+ | +-------------|-|-----------|-+   |     |   +-----|-----|-+ |   |   +-----|-----|-------|---------+ | | | | | | |   | | | | |       | | | 
+             | |   | |       |   |   |       |         | | | | |   |         | |     |     |     |     |         |     | | |   |         |     |       |           | | | | | | |   | | | | |       | | | 
+ +-------------------------------|---|-------|---------|-|-|-------|-----------------|-----|---+ |     |   +---------------|---|---------|-----|---------------------+ | | | | |   | | | | |       | | | 
+ |           | |   | |       |   |   |       |         | | | | |   |         | |     |     |   | |     |   |     |     | | |   |         |     |       |           |   | | | | |   | | | | |       | | | 
+ |           | |   | |       | +-|-----------|---------|---|-------|---------|-------------|---------------|-----|---------|---|-------------------------------+   | +-|-|---|-|---+ | | | |       | | | 
+ |           | |   | |       | | |   |       |         | | | | |   |         | |     |     |   | |     |   |     |     | | |   |         |     |       |       |   | | | | | | |     | | | |       | | | 
+ |           | |   | |       | | | +-|-------|-----------|-|-|-|---|---------|-|---------------|-------|-------------------|-------------|-------------+       |   | | | | | | |     | | | |       | | | 
+ |           | |   | |       | | | | |       |         | | | | |   |         | |     |     |   | |     |   |     |     | | |   |         |     |               |   | | | | | | |     | | | |       | | | 
+ |           | |   | |       | | +-|-------------------|-|---|-----|-----------|-----|---------|-----------------|-------|-|---|---------|-----|-------------------|-+ | | | | |     | | | |       | | | 
+ |           | |   | |       | |   | |       |         | | | | |   |         | |     |     |   | |     |   |     |     | | |   |         |     |               |   |   | | | | |     | | | |       | | | 
+ |       +---|-|-----|-------|-------|-----------------------|-|---|---------|-----+ |     |   | |     |   +-+   |     | | |   |       +-|-----|---+           |   |   | | | | |     | +-|-------+ | | | 
+ |       |   | |   | |       | |   | |       |         | | | | |   |         | |   | |     |   | |     |     |   |     | | |   |       | |     |   |           |   |   | | | | |     |   | |     | | | | 
+ |       |   | |   | |       | |   | |       |         | | | | |   |         | |   | |     |   | | +---|---------|-----|-------|---------|---------|-----+     |   |   | | | | +---+ | +-----+   | | | | 
+ |       |   | |   | |       | |   | |       |         | | | | |   |         | |   | |     |   | | |   |     |   |     | | |   |       | |     |   |     |     |   |   | | | |     | | | | | |   | | | | 
+ |       |   | |   | |       | | +-|---------------------|---|-|---|-----------|---|-------|-----|-----|-----|-----------|-|---|---------|---------------|-+   |   |   | | | | +-+ | | | | | +-+ | | | | 
+ |       |   | |   | |       | | | | |       |         | | | | |   |         | |   | |     |   | | |   |     |   |     | | |   |       | |     |   |     | |   |   N   | | | | | | | | | | |   | | | | | 
+ |       | +-|-----|-|-------|-|-|---+       |         | | | | |   |         | |   | |     |   | | |   |     |   +-----|---|---|-----+ | |     |   |     | | +-|---|---|-------+ A | | | | | +---|-+ | | 
+ |       | | | |   | |       | | | |         |         | | | | X   |         | |   | |     |   | | |   |     |         | | |   |     | | |     |   |     | | | |   |   | | | |     | | | | | | | |   | | 
+ |       | | | |   | |       +-|-----------------------|-------|-------------|-|-----|-----|-----|---------------------|---|---------|---|-----------------|-|-----+   | | | |     | | +-----+ | |   | | 
+ |       | | | |   | |         | | |         |         | | | | |   |         | |   | |     |   | | |   |     |         | | |   |     | | |     |   |     | | | |       | | | |     | |   | |   | |   | | 
+ |       | | | |   | |         +-------------|---------|-|---|-|---|---------------|-|-----|---|-------------------------|-|-----------|-|---------------|-|-------------|-|-------|-+   | |   | |   | | 
+ |       | | | |   | |           | |         |         | | | | |   |         | |   | |     |   | | |   |     |         | | |   |     | | |     |   Y     | | | |       | | | |     |     | |   | |   | | 
+ +-------|-----|---+ |     +-----|-|-------+ |         | | | | |   |   +-----------|-|-------------|-------------+ +-------|---------|-------------|---------|---------+ | | | +-+ |     | +---|-|-----+ 
+         | | | |     |     |     | |       | |         | | | | |   |   |     | |   | |     |   | | |   |     |   | |   | | |   |     | | |     |   |     | | | |         | | | | | |     |     | |   |   
+         | | | |     |     |     | |       | |         | +---|---------|-----|-----|-------|-------|---------------|-----+ |   |     | | |     |   |     | | | | +---+ +-----|-+ | +-----------|-+   |   
+         | | | |     |     |     | |       | |         |   | | |   |   |     | |   | |     |   | | |   |     |   | |   |   |   |     | | |     |   |     | | | | |   | | | | |   |       |     |     |   
+         +-|---|-----+     |     | |       | | +-------|-----+ |   |   |     | |   | |     |   | | |   |     |   | |   | +-|---------|-|-------|---|---------|-+ | +-------|-----|-+     |     |     |   
+           | | |           |     | |       | | |       |   |   |   |   |     | |   | |     |   | | |   |     |   | |   | | |   |     | | |     |   |     | | |   | | | | | | |   | |     |     |     |   
+           | | | +---+     |     | |       | +-+       |   |   |   |   |     | +-----------|-----|-----------|-------+ | | |   |     | | |     |   |     | | |   | | +-----|-|-----|-------+   |     |   
+           | | | |   |     |     | |       |           |   |   |   |   |     |     | |     |   | | |   |     |   | | | | | |   |     | | |     |   |     | | |   | |   | | | |   | |     | |   |     |   
+           | | | |   |     |     | |       |           |   |   |   |   |     +-------|-----|---|-|-|-------------|-|-|-------+ | +---|-|-|---------|-------+ +-+ | | +-|-|---|-+ | |     | |   |     |   
+           | | | |   |     |     | |       |           |   |   |   |   |           | |     |   | | |   |     |   | | | | | | | | |   | | |     |   |     |     | | | | | | | | | | |     | |   |     |   
+     +-----+ | | +---------|-----+ |       |           +-------|-+ |   |           | |     |   | | |   |   +---------|-|---|-|-------|---|-----|---|-------+ +-----|-----+ | | | +-|-----|-+   |     |   
+     |       | |     |     |       |       |               |   | | |   |           | |     |   | | |   |   | |   | | | | | | | | |   | | |     |   |     | | | | | | | |   | | |   |     |     |     |   
+     |       | |     +-------------|-------|---------------|-----|-----|-----------|-------|---|---|---|-----|-----|-----|---|-|-|---|-|-|-----|---------|-|-|-|-|-|-|-|---|-|---+ +-----|-----+     |   
+     |       | |           |       |       |               |   | | |   |           | |     |   | | |   |   | |   | | | | | | | | |   | | |     |   |     | | | | | | | |   | | | |       |           |   
+     |       | |           |   +---|-------|-------------------+ | |   |           | |     |   | | |   |   | |   | | | | | | | | |   | | |     | +-|-----------+ | | | |   | | | | +-------------+   |   
+     |       | |           |   |   |       |               |     | |   |           | |     |   | | |   |   | |   | | | | | | | | |   | | |     | | |     | | |   | | | |   | | | | |     |       |   |   
+     +---------|---------------|---|-------|---------------|-------|-----+         | | +---|---|-|-|---|-----|---|-|-----|---|---|---|-|-----------|-----|---|---|-+ | |   | | | | |     |     +-|-+ |   
+             | |           |   |   |       |               |     | |   | |         | | |   |   | | |   |   | |   | | | | | | | | |   | | |     | | |     | | |   |   | |   | | | | |     |     | | | |   
+             | |           |   | +-|-------|---------------------|-----------------|-|-----|-----------------|-----|---|-|-|---|---------------|-+ |     | | |   |   | |   | | | | |     |     | | | |   
+             | |           |   | | |       |               |     | |   | |         | | |   |   | | |   |   | |   | | | | | | | | |   | | |     |   |     | | |   |   | |   | | | | |     |     | | | |   
+             | |   +-------|-----|---------|---------------|-------|---|-|-----------|-|---|-----+ |   |   | |   | | | | | | | | |   | | |     |   |     | | |   |   | |   | | | | |     |     | | | |   
+             | |   |       |   | | |       |               |     | |   | |         | | |   |   |   |   |   | |   | | | | | | | | |   | | |     |   |     | | |   |   | |   | | | | |     |     | | | |   
+             | | +-|-------|---|-|-|-----+ |               +-----|-------------------+ |   |   |   |   |   +-|-----|-------+ | | |   | | |     |   |     | | |   |   | |   | | | | |     | +-+ | | +-|-+ 
+             | | | |       |   | | |     | |                     | |   | |         |   |   |   |   |   |     |   | | | | |   | | |   | | |     |   |     | | |   |   | |   | | | | |     | | | | |   | | 
+             | | | +-----------|---|-------|-+                   | |   | |         |   |   |   |   |   |     |   | | | | |   | | +---|---+     |   |     | | |   |   | |   | | | | |     | | | | |   | | 
+             | | |         |   | | |     | | |                   | |   | |         |   |   |   |   |   |     |   | | | | |   | |     | |       |   |     | | |   |   | |   | | | | |     | | | | |   | | 
+             | | |   +-----|---|---|-----|-|---------------------|-|-----------------------------------|-----|---|-|---|-|-----|-----|-|-------|---|---------|---|---|-------|-|-----------|-|-|-|---|-+ 
+             | | |   |     |   | | |     | | |                   | |   | |         |   |   |   |   |   |     |   | | | | |   | |     | |       |   |     | | |   |   | |   | | | | |     | | | | |   |   
+ +-------------|---------------|---|-----|-|-------------------+ | |   | |         |   |   |   |   |   |     |   | | +-|-|-----|-+   | |       |   |     | | |   |   | |   | | | | |     | | | | |   |   
+ |           | | |   |     |   | | |     | | |                 | | |   | |         |   |   |   |   |   |     |   | |   | |   | | |   | |       |   |     | | |   |   | |   | | | | |     | | | | |   |   
+ |           | | |   |     |   | | |     | | | +-------+       | | |   | |         |   |   | +-|-------------|---------|-|---|-|-----|-|-----------|-----|-|-------+ | +---------+ | +-------|-|---+ |   
+ |           | | |   |     |   | | |     | | | |       |       | | |   | |         |   |   | | |   |   |     |   | |   | |   | | |   | |       |   |     | | |   | | |     | | |   | |   | | | | | | |   
+ |           | | |   |     |   | | |     | | | |       |       | | |   | |         |   |   | | |   |   |     |   | |   +-|---|---+   | |       |   |     | | |   | | |     | | |   | |   | | | | | | |   
+ |           | | |   |     |   | | |     | | | |       |       | | |   | |         |   |   | | |   |   |     |   | |     |   | |     | |       |   |     | | |   R | |     | | |   | |   | | | | | | |   
+ |           | | |   |     |   | +-|-----|---+ |       |       | | |   | |         |   |   | | | +-----|---------|-------|---|-----+ | |       |   |     | | |   | | |     | | |   | |   +-|-|-+ | | |   
+ |           | | |   |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | | |   | | |     | | |   | |     | |   | | |   
+ |           | | |   |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | | +---+ | |     | | |   | |     | |   | | |   
+ |           | | |   |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     | |   | | |   
+ |           | | |   |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     | |   | | |   
+ |           | | |   |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     | |   | | |   
+ |           | | | +-|---------------------|-------------------|-------|-|---------|---|---|---|-------------|---|-|---------|-------|---------|---------|-|-------|-|-------|-------|-----|-+   | | |   
+ |           | | | | |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   |     | |   |       |       | | |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   | +---------------------------+ |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   | |   | |   J       |       |   |   | |         |   |   | | | | |   |     |   | |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   | |   | |   |       |       |   |   | |         |   |   | | +-|-|---------|---+ |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |           | | | | |     |   |   | |   | |   |       |       |   |   | |         |   |   | |   | |   |     |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |         +-----|-|-|-----|-------|-|---|-|-----------+       |   |   | |         |   |   | |   | |   |     |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |         | | | | | |     |   |   | |   | |   |               |   |   | |         |   |   | |   | |   |     |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |         | | | | | |     |   |   | |   | |   |               |   |   | |   +-------------|-------|---|---+ |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ |         | | | | | |     |   |   | |   | |   |               |   |   | |   |     |   |   | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ | +-------|-----|-+ |     |   |   | |   | |   |               |   |   | |   |     |   |   | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ | |       | | | |   |     |   |   | |   | |   |               |   |   | |   |     |   |   | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | |     | | |   | |     |     | | |   
+ | |     +---|-|-----|-----+   |   | |   | |   |     +---------|---------|---|-----|---|---|-------|---|---|-------|---------|-------|-|-------|-----------|-------|---+   | | |   | |   +---------+ |   
+ | |     | | | | |   |         |   | |   | |   |     |         |   |   | |   |     |   |   | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | | |   | | |   | |   | |     |   |   
+ | +---------|---|-------------|---------|-|---|---------------|---|---|-----|-+   |   +-----|---|-|---|---|-------|-----|---------|---|-------|---|-------|-------|-|-------|---+ | |   | |     |   +-+ 
+ |       | | | | |   |         |   | |   | |   |     |         |   |   | |   | |   |       | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | | |   | | | | | |   | |     |     | 
+ | +-----|-+ | | | +-|-----+   |   | |   | |   |     |         |   |   | |   | |   |       | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | | |   | | | | | |   | |     |     | 
+ | |     |   | | | | C     |   |   | |   | |   |     |         |   |   | |   | |   |       | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | | |   | | | | | |   | |     |     | 
+ | |     | +---|-+ +-------|---|---------|-|---------|-------------------|---|-----|-------|-------|---|---|-|-----|-----|-----|---|-|-|-------|---------------------|-----|-----|-+ |   | |     |     | 
+ | |     | | | |     |     |   |   | |   | |   |     |         |   |   | |   | |   |       | |   | |   |   | |     |     |   | |   | | |       |   |     | |       | | |   | | | |   |   | |     |     | 
+ | +-----|-|-|-|---+ |     |   |   | |   | |   |     |       +-|-------|-----|-|-------------|---------|---|-|-----|---------------|---------------------+ |       | | |   | | | |   |   | |     |     | 
+ |       | | | |   | |     |   |   | |   | |   |     |       | |   |   | |   | |   |       | |   | |   |   | |     |     |   | |   | | |       |   |       |       | | |   | | | |   |   | |     |     | 
+ | +-------|-----+ +-|-----|---|-----|---|-----|-----|---------|---|---|-|-------------------|---|---------+ |     |     |   | |   | | |       |   |       |       | | |   | | | |   |   | |     |     | 
+ | |     | | | | |   |     |   |   | |   | |   |     |       | |   |   | |   | |   |       | |   | |   |     |     |     |   | |   | | |       |   |       |       | | |   | | | |   |   | |     |     | 
+ +-|-----------|-|-+ |     |   |   | |   | |   |     |       | |   |   | |   | |   |       | |   | |   |     |     |     |   | |   | | |       |   |       |       | | +---|-|-+ |   |   | |     |     | 
+   |     | | | | | | |     |   |   | |   | |   |     |       | |   |   | |   | |   |       | |   | |   |     |     |     |   | |   | | |       |   |       |       | |     | |   |   |   | |     |     | 
+   +-+   | | | | +-|-------|---|---|-----|-|---------|-------|-----------|-----|-------------------|---|-----|-----+     |   | |   | | |       |   |       |       | +-----|-|--D----|---|-+     |     | 
+     |   | | | |   | |     |   |   | |   | |   |     |       | |   |   | |   | |   |       | |   | |   |     |           |   | |   | | |       |   |       |       |       | |   |   |   |       |     | 
+     |   | | | |   | |     |   |   | |   | | +-|-------------|-|---|---|-------+   |       +-------|---|-----|-----------|-----|---------------|-+ |       |       |       | |   |   |   |       |     | 
+     |   | | | |   | |     |   |   | |   | | | |     |       | |   |   | |   |     |         |   | |   |     |           |   | |   | | |       | | |       |       |       | |   |   |   |       |     | 
+     |   | | | |   | |     |   |   | |   | | | |     |       | |   |   | |   |     | +-----------|-----|-----|---------------------|-------------|-|-------+       |       | |   |   |   |       |     | 
+     |   | | | |   | |     |   |   | |   | | | |     |       | |   |   | |   |     | |       |   | |   |     |           |   | |   | | |       | | |               |       | |   |   |   |       |     | 
+     |   | | | |   +-|---------|---|-|---|-+ | |     |       | |   +---|-|---|-------|-------|---|-|---|---------------------+ |   | | |       | +-------------------------|-|---+   |   |       |     | 
+     |   | | | |     |     |   |   | |   |   | |     |       | |       | |   |     | |       |   | |   |     |           |     |   | | |       |   |               |       | |       |   |       |     | 
+     |   | | | |     |     |   |   | |   |   | |     |       | |       | |   |     | |       |   | |   |     |           | +---|---|-------------------------------|-------------+   |   |       |     | 
+     |   | | | |     |     |   |   | |   |   | |     |       | |       | |   |     | |       |   | |   |     |           | |   |   | | |       |   |               |       | |   |   |   |       |     | 
+ +---+ +-+ +---------|---------------|---|-----------------+ | |       | |   |     | |       |   | |   |     |           | |   |   | | |       |   |               |       | +-------|-----------|-----+ 
+ |     |     | |     |     |   |   | |   |   | |     |     | | |       | |   |     | |       |   | |   |     |           | |   |   | | |       |   |               |       |     |   |   |       |       
+ |     |     +-|-----|-----|---|---|-|-------|-------------|-|---------|-------+   | |       |   | |   |     |           | |   |   | | |       |   |               |       |     |   |   |       +-----+ 
+ |     |       |     |     |   |   | |   |   | |     |     | | |       | |   | |   | |       |   | |   |     |           | |   |   | | |       |   |               |       |     |   |   |             | 
+ |     |       |     |     |   +---------------------|---------|-------------|-|-------------|---|-|-----------------------|---|---+ | |       |   |               |       |     |   |   |             | 
+ |     |       |     |     |       | |   |   | |     |     | | |       | |   | |   | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |             | 
+ |     |       |     |     |       | |   |   | |     |     | | |       | |   | |   | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |             | 
+ |     |       |     |     |       | |   |   | |     |     | | |       | |   | |   | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |             | 
+ |     |       | +---|-------------|-----|---|-|-----|-------------------|-----+   | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |             | 
+ |     |       | |   |     |       | |   |   | |     |     | | |       | |   |     | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |             | 
+ +-+   | +-+   | |   |     |       | |   |   | |     +-----|-------------|---|-----|-|-------|-----------------------------|---|-----|-|-------|---------------------------|-----|-------|-------------+ 
+   |   | | |   | |   |     |       | |   |   | |           | | |       | |   |     | |       |   | |   |     |           | |   |     | |       |   |               |       |     |   |   |               
+ +-----|-|-------|---------|---------|---|-------------------|-----------|-----------|-----------------------------------|-|---------|-|-------|-----------------+ |       |     |   |   |               
+ | |   | | |   | |   |     |       | |   |   | |           | | |       | |   |     | |       |   | |   |     |           | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | | |   | |   |     |       | |   |   | +-----------|-|-----------|---|-----|-------------|-----|-----|---------+ | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | | |   | |   |     |       | |   |   |             | | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | | +-+ | |   |     |       | |   |   |             | | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | |   | | |   |     |       | |   |   |             | | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | |   | | |   |     |       | |   |   |             | | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | |   | | |   |     |       | |   |   |             | | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |             | |       |     |   |   |               
+ | |   | |   | | |   |     |       | |   |   |   +---------+ | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |       +-----|---------------+   |   |               
+ | |   | |   | | |   |     |       | |   |   |   |           | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |       |     | |       |         |   |               
+ | +---|-+ +-|-------------|-------------------+ |           | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |       |     | |       |         |   |               
+ |     |   | | | |   |     |       | |   |   | | |           | |       | |   |     | |       |   | |   |     |         | | |   |     | |       |   |       |     | |       |         |   |               
+ | +---+ +-|---|-----+     |       | |   |   | | |           | +-----------------------------|-+ | |   |     |         | | |   +-----|-|-------|-+ |       |     | |       |         |   |               
+ | |     | | | | |         |       | |   |   | | |           |         | |   |     | |       | | | |   |     |         | | |         | |       | | |       |     | |       |         |   |               
+ | |     | | | | |         |       | +---|---|-|-------------|---------|-----------------------|-------|-----|-----------|-------------|-------|-|---------|-------|-------|---------+   |               
+ | |     | | | | |         |       |     |   | | |           |         | |   |     | |       | | | |   |     |         | | |         | |       | | |       |     | |       |             |               
+ | |     | | | | |         |       |     |   | | |           |         | |   |     | |       | | | |   |     |         | | |         | |       | | |       +-------|-------|-------+     |               
+ | |     | | | | |         |       |     |   | | |           |         | |   |     | |       | | | |   |     |         | | |         | |       | | |             | |       |       |     |               
+ | |     | | | | |         |       |     |   | | |           |         | |   |     | |       | | | |   |     |         +-|-|---------|-------------|-------------|---------------------------------+     
+ | |     | | | | |         |       |     |   | | |           |         | |   |     | |       | | | |   |     |           | |         | |       | | |             | |       |       |     |         |     
+ | |     | | | | |         |       |     |   | | |           |         | +---|-----|-|-------|---|-|---------|-----------|-|-----------+       | | +-------------------------------|-----+         |     
+ | |     | | | | |         |       |     |   | | |           |         |     |     | |       | | | |   |     |           | |         |         | |               | |       |       |               |     
+ | |     +---|-|-|---------------+ |     |   | | | +-------------------|-+   |     | |       | | | |   |     |           | |         |         | |               | |       |       |               |     
+ | |       | | | |         |     | |     |   | | | |         |         | |   |     | |       | | | |   |     |           | |         |         | |               | |       |       |               |     
+ +-+   +-+ | | | |         |     | |     |   | | | |         |         | |   |     | |       | +-+ |   |     +-------------+         |         | |               | |       |       |               |     
+       | | | | | |         |     | |     |   | | | |         |         | |   |     | |       |     |   |                 |           |         | |               | |       |       |               |     
+ +-------+ | +-|-|-+       |     | |     | +-----|-|---------|-----------|---------|-|-------|---------|-----------------------------|-----------+               | |       |       +---------------|---+ 
+ |     |   |   | | |       |     | |     | | | | | |         |         | |   |     | |       |     |   |                 |           |         |                 | |       |                       |   | 
+ |   +---------+ | |       |     +-|-------|-----|-----------|-----------|---|-------|-----+ |     |   |                 |           |         |                 | |       |                       |   | 
+ |   | |   |     | |       |       |     | | | | | |         |         | |   |     | |     | |     |   |                 |           |         |                 | |       |                       |   | 
+ |   | | +-|-----|-|---------------|-----|-|---|-----------------------|-----|-----+ |     +-|-----|---|-----------------|---------------------+                 | |       |                       |   | 
+ |   | | | |     | |       |       |     | | | | | |         |         | |   |       |       |     |   |                 |           |                           | |       |                       |   | 
+ |   | | | | +-------------+       |     +-|-+ | | |         |         | |   |       |       | +-------|-----------------|-----------+                           | |       |                       |   | 
+ |   | | | | |   | |               |       |   | | |         |         | |   |       |       | |   |   |                 |                                       | |       |                       |   | 
+ | +---|-|-+ |   | | +-------------|-------|---|---|-------------------+ |   +-----+ |       | +---|---------------------|---------------------------------------|-|-----------------------------------+ 
+ | | | | |   |   | | |             |       |   | | |         |           |         | |       |     |   |                 |                                       | |       |                       |     
+ +-|-------------|---+         +---|-------+ +---|-|---------------------|-----------|-------------|---|-----------------|---------------------------------------|-|-------|---------------------------+ 
+   | | | |   |   | |           |   |         | | | |         |           |         | |       |     |   |                 |                                       | |       |                       |   | 
+   | | | |   |   | |       +-------------+   | | | |         |           |         | |       +-----|---------------------|-----------------------------------------|-----------------------------------+ 
+   | | | |   |   | |       |   |   |     |   | | | |         |           |         | |             |   |                 |                                       | |       |                       |     
+   | | | +---|-----|----------F----|-----|---+ | | +-+       |           |         | |             |   |                 |   +-----------------------------------|-------------------------------------+ 
+   | | |     |   | |       |   |   |     |     | |   |       |           |         | |             |   |                 |   |                                   | |       |                       |   | 
+   | +-|-----|-----------------|-----------------------------|-----------------------|-------------|---------------------|---|---------------------+             | |       |                 +-+   | +-+ 
+   |   |     |   | |       |   |   |     |     | |   |       |           |         | |             |   |                 |   |                     |             | |       |                 | |   | |   
+   |   |     |   | |       |   |   +-----------|-|-----------|-----------|---------|-|-------------|---|---------------------|---------------------+             | |       |                 | |   | |   
+   |   |     |   | |       |   |         |     | |   |       |           |         | |             |   |                 |   |                                   | |       |                 | |   | |   
+   |   |     |   | |       +---|---------|-------+   |       |           |         | |             |   |                 +---------------------------------------|---------------------------+ |   | |   
+   |   |     |   | |           |         |     |     |       |           |         | |             |   |                     |                                   | |       |                   |   | |   
+   |   |     |   | +-----------+         |     +-+   |       |           +---------|-------------------|---------------------+         +---------------------------+       |                   |   | |   
+   |   |     |   |                       |       |   |       |                     | |             |   |                               |                         |         |                   |   | |   
+ +-+   |   +-----|-----------------------|-------|---|-------+                     +-+             +---|-------------------------------+                         |     +---+                   |   +-+   
+ |     |   | |   |                       |       |   |                                                 |                                                         |     |                       |         
+ +-----+   +-+   +-----------------------+       +---+                                                 +---------------------------------------------------------+     +-----------------------+         
+                                                                                                                                                                                                         
\ No newline at end of file
diff --git a/problems/day19.html b/problems/day19.html
new file mode 100644 (file)
index 0000000..2f66538
--- /dev/null
@@ -0,0 +1,165 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 19 - Advent of Code 2017</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
+<link rel="stylesheet" type="text/css" href="/static/style.css?12"/>
+<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
+<link rel="shortcut icon" href="/favicon.ico?2"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  The best surprises don't
+even appear in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not Google, and I can only take
+so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, ads, social media),
+I built the whole thing myself, including the design, animations, prose, and
+all of the puzzles.
+
+The puzzles probably took the longest; the easiest ones took an hour or two
+each, but the harder ones took 4-5 hours, and a few even longer than that. A
+lot of effort went into building this thing - I hope you're enjoying playing it
+as much as I enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2017/about">[About]</a></li><li><a href="/2017/support">[AoC++]</a></li><li><a href="/2017/events">[Events]</a></li><li><a href="/2017/settings">[Settings]</a></li><li><a href="/2017/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="supporter">(AoC++)</span> <span class="star-count">38*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0x0000|</span><a href="/2017">2017</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2017">[Calendar]</a></li><li><a href="/2017/leaderboard">[Leaderboard]</a></li><li><a href="/2017/stats">[Stats]</a></li><li><a href="/2017/sponsors">[Sponsors]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2017/sponsors">sponsors</a> help make Advent of Code possible:</div><p><a href="http://kx.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Kx Systems</a> - kdb+, the in-memory time series technology standard</p></div>
+<p class="quiet">By popular demand, there are now AoC-themed objects available (until Jan. 3rd)! Get them shipped <a href="https://teespring.com/advent-of-code" target="_blank">from the US</a> or <a href="https://teespring.com/advent-of-code-eu" target="_blank">from Europe</a>.</p>
+
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 19: A Series of Tubes ---</h2><p>Somehow, a network packet got <span title="I know how fast it's going, but I don't know where it is.">lost</span> and ended up here.  It's trying to follow a routing diagram (your puzzle input), but it's confused about where to go.</p>
+<p>Its starting point is just off the top of the diagram. Lines (drawn with <code>|</code>, <code>-</code>, and <code>+</code>) 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.</p>
+<p>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 <em>letters</em> 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:</p>
+<pre><code>     |          
+     |  +--+    
+     A  |  C    
+ F---|----E|--+ 
+     |  |  |  D 
+     +B-+  +--+ 
+
+</code></pre>
+<p>Given this diagram, the packet needs to take the following path:</p>
+<ul>
+<li>Starting at the only line touching the top of the diagram, it must go down, pass through <code>A</code>, and continue onward to the first <code>+</code>.</li>
+<li>Travel right, up, and right, passing through <code>B</code> in the process.</li>
+<li>Continue down (collecting <code>C</code>), right, and up (collecting <code>D</code>).</li>
+<li>Finally, go all the way left through <code>E</code> and stopping at <code>F</code>.</li>
+</ul>
+<p>Following the path to the end, the letters it sees on its path are <code>ABCDEF</code>.</p>
+<p>The little packet looks up at you, hoping you can help it find the way.  <em>What letters will it see</em> (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.)</p>
+</article>
+<p>Your puzzle answer was <code>XYFDJNRCQA</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>The packet is curious how many steps it needs to go.</p>
+<p>For example, using the same routing diagram from the example above...</p>
+<pre><code>     |          
+     |  +--+    
+     A  |  C    
+ F---|--|-E---+ 
+     |  |  |  D 
+     +B-+  +--+ 
+
+</code></pre>
+<p>...the packet would go:</p>
+<ul>
+<li><code>6</code> steps down (including the first line at the top of the diagram).</li>
+<li><code>3</code> steps right.</li>
+<li><code>4</code> steps up.</li>
+<li><code>3</code> steps right.</li>
+<li><code>4</code> steps down.</li>
+<li><code>3</code> steps right.</li>
+<li><code>2</code> steps up.</li>
+<li><code>13</code> steps left (including the <code>F</code> it stops on).</li>
+</ul>
+<p>This would result in a total of <code>38</code> steps.</p>
+<p><em>How many steps</em> does the packet need to go?</p>
+</article>
+<p>Your puzzle answer was <code>17450</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
+<p>At this point, you should <a href="/2017">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="19/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22A+Series+of+Tubes%22+%2D+Day+19+%2D+Advent+of+Code+2017&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F19&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F19" target="_blank">Google+</a>
+  <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F19&amp;title=I%27ve+completed+%22A+Series+of+Tubes%22+%2D+Day+19+%2D+Advent+of+Code+2017" target="_blank">Reddit</a
+></span>]</span> this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file
diff --git a/src/advent19/advent19.hs b/src/advent19/advent19.hs
new file mode 100644 (file)
index 0000000..98f6d21
--- /dev/null
@@ -0,0 +1,89 @@
+{-# LANGUAGE NegativeLiterals #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TypeFamilies #-}
+
+import Prelude hiding (Left, Right)
+import Data.List
+import Data.Char
+
+type Maze = [String]
+
+data Direction = Up | Down | Left | Right deriving (Show, Eq)
+
+data Progress = Progress { row :: Int
+                         , column :: Int
+                         , direction :: Direction
+                         , letters :: String
+                         , stepCount :: Int
+                         } deriving (Show, Eq)
+
+
+-- Note: assumes the maze comes with a padding border of spaces
+-- all around it. Makes the "next location" checking much easier!
+
+main :: IO ()
+main = do 
+        text <- readFile "data/advent19.txt"
+        let maze = lines text
+        let progress = navigate maze
+        print $ letters progress
+        print $ stepCount progress
+
+
+startProgress :: Maze -> Progress
+startProgress maze = Progress { row = 0, column = startCol
+                              , direction = Down
+                              , letters = "", stepCount = 0}
+    where topRow = maze!!0
+          startCol = head $ elemIndices '|' topRow  
+
+delta :: Direction -> (Int, Int)
+delta Up    = (-1,  0)
+delta Down  = ( 1,  0)
+delta Left  = ( 0, -1)
+delta Right = ( 0,  1)
+
+isJunction '+' = True
+isJunction  _  = False 
+
+isFinished :: Maze -> Progress -> Bool
+isFinished maze progress = isSpace $ location maze (row progress) (column progress)
+
+location :: Maze -> Int -> Int -> Char
+location maze r c = (maze!!r)!!c
+
+
+navigate :: Maze -> Progress
+navigate maze = navigate' maze progress
+    where progress = startProgress maze
+
+navigate' :: Maze -> Progress -> Progress
+navigate' maze progress = 
+    if isFinished maze progress 
+        then progress
+        else navigate' maze (step maze progress)
+
+
+step :: Maze -> Progress -> Progress
+step maze progress = progress {row = r', column = c', direction = d', letters = l', stepCount = sc'}
+    where r = row progress
+          c = column progress
+          thisChar = location maze r c
+          l' = if isAlpha thisChar then (letters progress) ++ [thisChar] else letters progress
+          d' = if isJunction thisChar then newDirection maze progress else direction progress 
+          (dr, dc) = delta d'
+          r' = r + dr
+          c' = c + dc
+          sc' = stepCount progress + 1
+
+newDirection :: Maze -> Progress -> Direction
+newDirection maze progress = 
+    if d == Up || d == Down 
+    then if isSpace leftChar then Right else Left
+    else if isSpace upChar then Down else Up
+    where d = direction progress
+          r = row progress
+          c = column progress
+          upChar = location maze (r - 1) c
+          leftChar = location maze r (c - 1)
diff --git a/src/advent19/advent19.ipynb b/src/advent19/advent19.ipynb
new file mode 100644 (file)
index 0000000..09dce02
--- /dev/null
@@ -0,0 +1,394 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "{-# LANGUAGE NegativeLiterals #-}\n",
+    "{-# LANGUAGE FlexibleContexts #-}\n",
+    "{-# LANGUAGE OverloadedStrings #-}\n",
+    "{-# LANGUAGE TypeFamilies #-}"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import Data.List\n",
+    "import Data.Char"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[\"     |          \",\"     |  +--+    \",\"     A  |  C    \",\" F---|----E|--+ \",\"     |  |  |  D \",\"     +B-+  +--+ \",\"                \"]"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "sampleText <- readFile \"sample-maze.txt\"\n",
+    "sample = lines sampleText\n",
+    "print sample"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "type Maze = [String]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "data Direction = Up | Down | Left | Right deriving (Show, Eq)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "data Progress = Progress { row :: Int\n",
+    "                         , column :: Int\n",
+    "                         , direction :: Direction\n",
+    "                         , letters :: String\n",
+    "                         , stepCount :: Int\n",
+    "                         } deriving (Show, Eq)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "startProgress :: Maze -> Progress\n",
+    "startProgress maze = Progress {row = 0, column = startCol, direction = Down, letters = \"\", stepCount = 0}\n",
+    "    where topRow = maze!!0\n",
+    "          startCol = head $ elemIndices '|' topRow"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "delta :: Direction -> (Int, Int)\n",
+    "delta Up    = (-1,  0)\n",
+    "delta Down  = ( 1,  0)\n",
+    "delta Left  = ( 0, -1)\n",
+    "delta Right = ( 0,  1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "isContinuation '|' = True\n",
+    "isContinuation '-' = True\n",
+    "isContinuation  _  = False\n",
+    "\n",
+    "isJunction '+' = True\n",
+    "isJunction  _  = False "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "location :: Maze -> Int -> Int -> Char\n",
+    "location maze r c = (maze!!r)!!c"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "newDirection :: Maze -> Progress -> Direction\n",
+    "newDirection maze progress = \n",
+    "    if d == Up || d == Down \n",
+    "    then if isSpace leftChar then Right else Left\n",
+    "    else if isSpace upChar then Down else Up\n",
+    "    where d = direction progress\n",
+    "          r = row progress\n",
+    "          c = column progress\n",
+    "          upChar = location maze (r - 1) c\n",
+    "--           downChar = location maze (r + 1) c\n",
+    "          leftChar = location maze r (c - 1)\n",
+    "--           rightChar = location maze r (c + 1)\n",
+    "          "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "step :: Maze -> Progress -> Progress\n",
+    "step maze progress = progress {row = r', column = c', direction = d', letters = l', stepCount = sc'}\n",
+    "    where r = row progress\n",
+    "          c = column progress\n",
+    "          thisChar = location maze r c\n",
+    "          l' = if isAlpha thisChar then (letters progress) ++ [thisChar] else letters progress\n",
+    "          d' = if isJunction thisChar then newDirection maze progress else direction progress \n",
+    "          (dr, dc) = delta d'\n",
+    "          r' = r + dr\n",
+    "          c' = c + dc\n",
+    "          sc' = stepCount progress + 1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "\n",
+    "isFinished :: Maze -> Progress -> Bool\n",
+    "isFinished maze progress = isSpace $ location maze (row progress) (column progress)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "navigate' maze progress = \n",
+    "    if isFinished maze progress \n",
+    "        then progress\n",
+    "        else navigate' maze (step maze progress)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "navigate :: Maze -> Progress\n",
+    "navigate maze = navigate' maze progress\n",
+    "    where progress = startProgress maze"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Progress {row = 3, column = 0, direction = Left, letters = \"ABCDEF\", stepCount = 38}"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "navigate sample"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 17,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "'+'"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "sample!!5!!8"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 18,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "False"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "isJunction '|'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Progress {row = 5, column = 8, direction = Right, letters = \"\", stepCount = 0}"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "pt = (startProgress sample) {row = 5, column = 8, direction = Right}\n",
+    "pt"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Up"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "newDirection sample pt"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 21,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Progress {row = 4, column = 8, direction = Up, letters = \"\", stepCount = 1}"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "step sample pt"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 25,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "part1 = letters "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 26,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "part2 = stepCount"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 27,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "main :: IO ()\n",
+    "main = do \n",
+    "        text <- readFile \"../../data/advent19.txt\"\n",
+    "        let maze = lines text\n",
+    "        let progress = navigate maze\n",
+    "        print $ part1 progress\n",
+    "        print $ part2 progress"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 28,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\"XYFDJNRCQA\"\n",
+       "17450"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "main"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "navigate "
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Haskell",
+   "language": "haskell",
+   "name": "haskell"
+  },
+  "language_info": {
+   "codemirror_mode": "ihaskell",
+   "file_extension": ".hs",
+   "name": "haskell",
+   "version": "8.0.2"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/src/advent19/sample-maze.txt b/src/advent19/sample-maze.txt
new file mode 100644 (file)
index 0000000..45d439b
--- /dev/null
@@ -0,0 +1,7 @@
+     |          
+     |  +--+    
+     A  |  C    
+ F---|----E|--+ 
+     |  |  |  D 
+     +B-+  +--+ 
+                
\ No newline at end of file