Add day 19 solution

This commit is contained in:
Wesley Moore 2017-12-20 07:58:43 +11:00
parent 632ea00e06
commit a2dcabfc80
5 changed files with 394 additions and 0 deletions

4
2017/day/19/Cargo.lock generated Normal file
View file

@ -0,0 +1,4 @@
[[package]]
name = "day19"
version = "0.1.0"

6
2017/day/19/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "day19"
version = "0.1.0"
authors = ["Wesley Moore <wes@wezm.net>"]
[dependencies]

201
2017/day/19/input Normal file
View file

@ -0,0 +1,201 @@
|
+-+ +-----------------------------+ +---+ +-------+ +-+ +-+ +-+ +-------+ +-+
| | | | | | | | | | | | | | | | |
+-------------+ | +-+ +-------------------------------|---|---|---------------------------------------------------------+ | | | | | | | | +-+ | |
| | | | | | | | | | | | | | | | | | | | |
| | | | | | +-+ +---+ | | | +-------------------------------------------------|-------------+ | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | |
+-------|-------------------|-|-+ | | +---+ I +-|---|-|---+ | | +-------------------------------------------------------------------|-|-----|---+ +-------+
| | | | | | | | | | | | | | | | | | | | | | | | | |
| | | +---------|-------------|---------+ +-|---------|---------|-----------+ | | | +---------|-|-------------------------------|-----+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +---|-------------|-------|---|-|-------------+ | | | +-------|-+ | | | +---------------------|-----|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | +---|---------|-----------|-------|---------------------|-------|-----------|-------------------------|-------|-------+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | +-----|---|-------|-------|-----|-----------------------------------------|---------|-------+ | +---------------------|-|-------------|---+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | +-|-|---------------|-|-----|-----|-|---+ | | | | | | | | | | | | +-------------+ +-------|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---------------------+ +-------|-----|---------------|-|-----|-----|-|-----------+ | | | +-----------------|-----|-----|---------------------------|-----|-----+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | +-|---|-------|---------------------|-------------------|---------|-----|-------|---|-|-------|-----------------------+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | +-----|---+ +-------|-----------------|-----------|-------+ | | +---|-------------|---------------------|---------|-|-----+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-+ +-|-----------|-------------|-|-|---------------------+ | | +-|-----------------|-----------|---+ +---------|---------------|-|-|-----------------|-------------|-----|-----|---|---------+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | +-|-|-+ | | | | | | | | | +---|-----+ | | | | | | | | | | +-----|-----|-----|---+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +---+ | | | | | | | +-|---|---|-|-----+ | +-------------|-----------|---+ | | | | | | | | | | | | | +-----------------------|-+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------------------------|---|---|---|---------------------|-------------------+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-+ | +-----|-----------|---|-|-|-------------+ +---|-+ | | | +-----+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | +-|-|-|---+ | | | | | | | | | | +-------------|-----------------|-|---|-|-|---|---------------|-|-|-|-----+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +---------|-|-----|-+ | | | | | | | | | +-------------------|----------------------C--|---------------+ | | | | | | | | | +-------|-----|-----+ | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | +-----------------|-------|-|---|-|-----------|-----|-|-|-|-----|-----------------|---|---------------------|-----|-----------|-------|-------|-----------|-----------|-----+ | | | | +-|-+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---|-+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | +---------------------|---|---------|---------+ | | | | +---+ | | | | | | | | | | +-|-----------------+ | | | +-------+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---------|-----|-|---+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | +---|---|-+ | | | +---+ | | | | | | | +-----|-----|---|-|-----------------|-----|---+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | +-|---|-------+ | | | | | | | | | | | | | | | | | | | | | | | | +-|-|---------+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | +-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---|-|---|-----|---|-|-+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | +-----+ +---------|---+ | | | | | | | | | | | | | | | | | | | +-|---+ | +-----|---+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------|-|---------------------------+ | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------|-----------------------|---------------|-|-----|-----|-|-|-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---|-|-+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-------------|-----|-----|-----|---------|---------|-|-|-|-------|-----|-+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-------|-----|---|---|-----|-----|-----------|---|-|---|-|-|-----|-----|---------------|-|-----------|-----|-----|-----|---------|-----|-----|-|-|-----|-|-----|---|-|-------+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | +-|---|---------|---|-------------------|-|-|---|-|---|-|-----------------|-----------|-|-----------|-----|-----|---------------------|-----------|---------|-----|---|---------|-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +---|---------|---|---|-----------|-----------------|---|---|------L----|-|-------+ | | | | | | | | | | | +-|-|-|---|-|---|-----|-|---+ | +---+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------|-|-----|-----------|-------|---+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | +-|-----------|-|---+ | +-------------|-----------------|---|-----|-|---|-|-----|---|-|---+ | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | +-------------|---|-------|-----|---------|---|-|-----|-----------+ | | | +-|-------|-------|-----|---+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|-|-------------|---|-+ | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | X | | | | | | | | | | |
| | | | | +---|-------|-----------------|---|-|-------------------|---------+ +-----|-------------|-----|-----|-----------------------|-|-------|---|-|---|-|-|-|-------+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+--B--|---------+ | | | | | | | | | | | | | | | | | | | | | | +-|-----------|---+ | | | | | | | | | | +-|---|---------+ | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | +---|-|-----------|---------|-------------|-------|-----|-|-|-----|---|-----------------------|-------|-|-------|-|-----|---|-----|-----|---|-----|-----|-|-----|---+ | +-|-|-|---+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | +-----------------------|-------|-|-|---------------|-------|-|-------+ | | | | | +-+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | +-----|-|-----------|-|---|-------------|---|-------|-----|---|-|---|-----|---------------|-----|-|-|-------|-|-------+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-------------|-|-|---------|---+ | | | | | | | | | | | | | +-|-----------------|-------+ | | | | | | | | | | | | | +---|---------|-----+ | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +---|-|-|---------|---------------------|---|-------|-----|-|-----|---+ +---|-------------|---|-------------------------|-|-|-----------|---|---------|-|-|---|-|---|---+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | +---|---------------------------------------|---------|-|---|-|---|-----|-----------|-|-----+ |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | +-|-|-----|-|-----------|-------------|-|-|---------|---|-----|-------|-----------|---|-------------+ | | | | | | | | | | | +-----|-|---+ | | +-|-|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-------|-|-------|-------------------------|---------|---|---------------------------------|---------------------|-|---|-|---|-----|-----|-------------|-|-----|-|-|---|---+ | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | +---------------------|---|-----------------|---------|-|---|---------------|---------|-------|---|---|-----------+ |
| | P | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | +-------------|-----|---|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | +-----|-|-|-|---|---|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | +-----|-----|-------|---|-----------------|-------------------------|---------------|-|---|-------|---|-----|---------|-+ | | | +-----|-|-|---|---------+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|-|-----|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +---------|---+ | +---|-----|---|-|-------------|-----|-------|-|---------|---+ | +-----|-----|-----|-|-|-------------+ | +---------|-------|---|-|-|-----|-+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | +-+ | | | | | +---------|-----|-|-------|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | +-----------|-----------|-----|-----|---|-|-----|---------|-----|-|-|-------|-|-+ | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | +-------------------|-----|---|-|-|-------------|-----------|---|-----|---+ | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-|-------------------|---------|-|---------------|-----|-|-----|-------|-|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | +-----|------H------+ | | | | | | | | | | +-|-----|---|-+ | | | +-+ | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|---|---------+ | | +-|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| +-----|-----|---------+ | | | | | | | | | | | | | | | | | | | +---------------|-----|-|---|-------------|---|-----|-|-----|-----------------+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | V | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-|-------------|-------+ | | | | | | | | | | | | | | | | | | | | +---------------|-------|-+ | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | +-------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+ | | | | | | | | +-------------|-------|---|-------+ | | | | +---|-|-|-----------|-|-------+ | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-----|-|-------------|---|---------------|-------|---|-------|---|-----|---|---------------------|---|---|-------------------|-----|---|-|-------|-------|-------|-+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | +---|-------------------|---------+ | | | | | | | +---+ | | +-|-+ | | | | | | | | | | | | +---|---------|-|-----+ | | +---------+ | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | +-------|-------------------+ +---------+ | | +-----|---|---|-+ | | | | | | | | | | +---------|---|---------|---|-+ | | | | | | | +-+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +-|-------|---|---+ +---------|-------------|-|-|-|-----|---|---|-|---------+ +-----|-----------------------------------|-----------|---|---|---|-|-------|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | |
+---|-----|-|-------|-------|---------------------------------|---|---------|-|-----|---|-----------------------|---------------|-|-----|---+ | | | | | | | | | | | +-+ | | +-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | +-----|-|-|-----|---|---------|---|-----------------------|-------|-|-----------|-|-|----------E------|-------|---|---+ | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +-------|-----------|---------------------------|-|-|---|---|-----------|---|-----+ | | | | | | | | | | | | | +---|-----------|---------|---+ | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | +-|-|-------------------------------|-|-|-------|-|---|---------|---------------+ | +---------------|---|---------|---------------------|---+ | | | | +-+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | +---------------------------------|-|-|---|---|-|---|-|-------|-----------|-------|-----------|---|-------------|---|-----|---|---|-----|-|-------|---+ | +-+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-----+ +-----+ | | | | | | | | | | | | | | | | | | +---|-+ | | | | | | +-----|-------|---------|-----------|-----+ | +---|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---------------------------|---+ | | | | | | | | | | +-------|-------|-----------|-------|---|-----------|-|---------------------|-----|-|---+ | +-------|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | +---|-----------|---|-|-----|-------|---|-|-----+ | | +-|---------|---|---------|-|---|-+ | | +-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-----------|-----|-------|---|---------------------------------|-------|---|-------|---------------|-----------|---+ | | | | | | | | | +-----|-+ | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---------------|-|-|---------|-----------------------------|-----|-|-------|-|---|-|---|---|-------|---------------|-------|---|-|-|---------|---+ | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | +-|---|-+ +-------------------------------+ | | | | | +-----|---|-------|---------------|-------|-------|---+ | | | +-----|-|---|-----------|-|---------------|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-----------|-----|-|---|-|---|-|---+ | | | | | | | | | | | | | | +---|---|---|-|-|-+ | | | | | +---|---------|-|-----|-|---|---+ +-----|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | +---------------|---|-------|---|-|-----|---|-----------|---|-|---------|-------|-|-|---+ | | +---+ | | | | +-+ | +---|-------------+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | +-------+ +-------|-----------------------------|---+ +-|-----------|-------+ | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---+ | | +-----|---------|---------|---------------|-------|-----|-+ | | | | | +---------|-----|-------|-------------|---------|-|-----------|-----|---+ | +-|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+---|-----+ | | | | | | | | | | | | | | | +-|---|-----|---|-----------|-------+ +-----|---|-----------------|-----|-------|-|---------------|-------|---+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | +---|---|-|-----|---+ | | | | | +---------|---|-------------------------------------|-|-------------------------|-|---+ | | | | +-------|-|-------+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | +---------|---------------|-----------|---|-------------|---------------|-----|-----------|---------+ | +-+ | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-----|-----|---------+ | | | | +---+ | | | +-----------------------|-----------------+ | | | | | | | | | | | | | +---------|---+ +-----|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| +---|-------|---|-+ | | +-------|---------------|-----------------------|---|---|-------------|-|-----------+ | | | | +-------|---|-|-+ | | +---|-----|-----------|---|---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | +-|-----------------------+ | +-----------|---------------+ | | | +-|-----|-|-------+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-----|-----------|-------|-------|---------------|-------|-------------+ | +---+ +-|-----|-------------------|-------------|-|-----|---+ +-+ | | | | | | | +---+ +-+ | | +---+ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | +---+ | | | | | | | +---------------|-----|-----------------------------------------|---------+ | | | +-------|-----------+ | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| +-----------|-------|---------------|-|-----|-------------------------------------|-------------------|-----------+ | +-----+ +-----------------------+ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |
| +---------------------------|-----|-------------------------------|-------|-----------------|-------------+ +-------------|-------------+ +-------|---+ | | |
| | | | | | | | | | | | | | | | | | | | | |
+-------------------|-----------------------|-|-----|---------------------------------------------+ +---------|---------------------------+ | | | +---|-+ | | | | |
| | | | | | | | | | | | | | | | | | | | | |
+-------+ +-+ +---------+ +-------------+ +---------|---------------------------|-----|---------------|-----------+ +---|-+
| | | | | | | | | |
+-------------------------------------+ +-----------------+ +-----|-------------------------------+ | |
| | | | | | | |
+-------------------------------------------------------------------------------------------+ +-+ +---------------+ +-+

26
2017/day/19/problem.txt Normal file
View file

@ -0,0 +1,26 @@
--- Day 19: A Series of Tubes ---
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.)

157
2017/day/19/src/main.rs Normal file
View file

@ -0,0 +1,157 @@
use std::io::Read;
use std::fs::File;
use std::ops::{Add, Sub};
enum Direction {
Up,
Down,
Left,
Right
}
use Direction::*;
impl Direction {
fn left(&self) -> Direction {
match *self {
Up => Left,
Down => Right,
Left => Down,
Right => Up
}
}
fn right(&self) -> Direction {
match *self {
Up => Right,
Down => Left,
Left => Up,
Right => Down
}
}
}
trait Move: Add + Sub + Sized {
fn move_x(&self, direction: &Direction) -> Self;
fn move_y(&self, direction: &Direction) -> Self;
}
impl Move for usize {
fn move_x(&self, direction: &Direction) -> Self {
match *direction {
Up | Down => *self,
Left => self - 1,
Right => self + 1,
}
}
fn move_y(&self, direction: &Direction) -> Self {
match *direction {
Up => self - 1,
Down => self + 1,
Left | Right => *self,
}
}
}
struct Diagram {
data: Vec<u8>,
width: usize,
height: usize,
stride: usize,
}
impl Diagram {
fn new(data: Vec<u8>) -> Self {
let width = data.iter().position(|&b| b == 0x0A).expect("no newlines?"); // \n
let stride = width + 1; // Theres 1 byte of padding (the newline on every row)
let height = data.len() / stride;
Diagram { data, width, height, stride }
}
fn char_at(&self, row: usize, col: usize) -> char {
self.data[row * self.stride + col] as char
}
fn start_col(&self) -> usize {
self.data.iter().position(|&b| b == 0x7C).expect("unable to find start position") // |
}
}
fn main() {
let mut input = Vec::new();
let mut file = File::open("input").expect("unable to open input file");
file.read_to_end(&mut input).expect("error reading input");
let diagram = Diagram::new(input);
println!("{}", navigate(&diagram));
}
// This is pretty ugly... can be improved
fn navigate(diagram: &Diagram) -> String {
let mut col = diagram.start_col();
let mut row = 0;
let mut direction = Down;
let mut path = String::new();
loop {
let c = diagram.char_at(row, col);
// println!("Visit ({}, {}): '{}'", col, row, c);
if c >= 'A' && c <= 'Z' {
path.push(c);
}
// Try continuing in the same direction
let next_col = col.move_x(&direction);
let next_row = row.move_y(&direction);
if diagram.char_at(next_row, next_col) != ' ' {
row = next_row;
col = next_col;
continue;
}
// Try turning left
let left = direction.left();
let next_col = col.move_x(&left);
let next_row = row.move_y(&left);
if diagram.char_at(next_row, next_col) != ' ' {
row = next_row;
col = next_col;
direction = left;
continue;
}
// Try turning right
let right = direction.right();
let next_col = col.move_x(&right);
let next_row = row.move_y(&right);
if diagram.char_at(next_row, next_col) != ' ' {
row = next_row;
col = next_col;
direction = right;
continue;
}
break;
}
path
}
#[test]
fn test_example() {
let data = b" |
| +--+
A | C
F---|----E|--+
| | | D
+B-+ +--+
";
let diagram = Diagram::new(data.to_vec());
assert_eq!(navigate(&diagram), "ABCDEF".to_string())
}