From a2dcabfc80501ff0812e0db01acefca7d1747eed Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Wed, 20 Dec 2017 07:58:43 +1100 Subject: [PATCH] Add day 19 solution --- 2017/day/19/Cargo.lock | 4 + 2017/day/19/Cargo.toml | 6 ++ 2017/day/19/input | 201 ++++++++++++++++++++++++++++++++++++++++ 2017/day/19/problem.txt | 26 ++++++ 2017/day/19/src/main.rs | 157 +++++++++++++++++++++++++++++++ 5 files changed, 394 insertions(+) create mode 100644 2017/day/19/Cargo.lock create mode 100644 2017/day/19/Cargo.toml create mode 100644 2017/day/19/input create mode 100644 2017/day/19/problem.txt create mode 100644 2017/day/19/src/main.rs diff --git a/2017/day/19/Cargo.lock b/2017/day/19/Cargo.lock new file mode 100644 index 0000000..d8c290d --- /dev/null +++ b/2017/day/19/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "day19" +version = "0.1.0" + diff --git a/2017/day/19/Cargo.toml b/2017/day/19/Cargo.toml new file mode 100644 index 0000000..8d86975 --- /dev/null +++ b/2017/day/19/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day19" +version = "0.1.0" +authors = ["Wesley Moore "] + +[dependencies] diff --git a/2017/day/19/input b/2017/day/19/input new file mode 100644 index 0000000..f18900e --- /dev/null +++ b/2017/day/19/input @@ -0,0 +1,201 @@ + | + +-+ +-----------------------------+ +---+ +-------+ +-+ +-+ +-+ +-------+ +-+ + | | | | | | | | | | | | | | | | | + +-------------+ | +-+ +-------------------------------|---|---|---------------------------------------------------------+ | | | | | | | | +-+ | | + | | | | | | | | | | | | | | | | | | | | | + | | | | | | +-+ +---+ | | | +-------------------------------------------------|-------------+ | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | + +-------|-------------------|-|-+ | | +---+ I +-|---|-|---+ | | +-------------------------------------------------------------------|-|-----|---+ +-------+ + | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | +---------|-------------|---------+ +-|---------|---------|-----------+ | | | +---------|-|-------------------------------|-----+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +---|-------------|-------|---|-|-------------+ | | | +-------|-+ | | | +---------------------|-----|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | +---|---------|-----------|-------|---------------------|-------|-----------|-------------------------|-------|-------+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | +-----|---|-------|-------|-----|-----------------------------------------|---------|-------+ | +---------------------|-|-------------|---+ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | +-|-|---------------|-|-----|-----|-|---+ | | | | | | | | | | | | +-------------+ +-------|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +---------------------+ +-------|-----|---------------|-|-----|-----|-|-----------+ | | | +-----------------|-----|-----|---------------------------|-----|-----+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | +-|---|-------|---------------------|-------------------|---------|-----|-------|---|-|-------|-----------------------+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | +-----|---+ +-------|-----------------|-----------|-------+ | | +---|-------------|---------------------|---------|-|-----+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-+ +-|-----------|-------------|-|-|---------------------+ | | +-|-----------------|-----------|---+ +---------|---------------|-|-|-----------------|-------------|-----|-----|---|---------+ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | +-|-|-+ | | | | | | | | | +---|-----+ | | | | | | | | | | +-----|-----|-----|---+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +---+ | | | | | | | +-|---|---|-|-----+ | +-------------|-----------|---+ | | | | | | | | | | | | | +-----------------------|-+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------------------------|---|---|---|---------------------|-------------------+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-+ | +-----|-----------|---|-|-|-------------+ +---|-+ | | | +-----+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | +-|-|-|---+ | | | | | | | | | | +-------------|-----------------|-|---|-|-|---|---------------|-|-|-|-----+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +---------|-|-----|-+ | | | | | | | | | +-------------------|----------------------C--|---------------+ | | | | | | | | | +-------|-----|-----+ | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | +-----------------|-------|-|---|-|-----------|-----|-|-|-|-----|-----------------|---|---------------------|-----|-----------|-------|-------|-----------|-----------|-----+ | | | | +-|-+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---|-+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | +---------------------|---|---------|---------+ | | | | +---+ | | | | | | | | | | +-|-----------------+ | | | +-------+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---------|-----|-|---+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | +---|---|-+ | | | +---+ | | | | | | | +-----|-----|---|-|-----------------|-----|---+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | +-|---|-------+ | | | | | | | | | | | | | | | | | | | | | | | | +-|-|---------+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | +-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---|-|---|-----|---|-|-+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | +-----+ +---------|---+ | | | | | | | | | | | | | | | | | | | +-|---+ | +-----|---+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------|-|---------------------------+ | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------|-----------------------|---------------|-|-----|-----|-|-|-+ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|---|-|-+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|-------------|-----|-----|-----|---------|---------|-|-|-|-------|-----|-+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-------|-----|---|---|-----|-----|-----------|---|-|---|-|-|-----|-----|---------------|-|-----------|-----|-----|-----|---------|-----|-----|-|-|-----|-|-----|---|-|-------+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | +-|---|---------|---|-------------------|-|-|---|-|---|-|-----------------|-----------|-|-----------|-----|-----|---------------------|-----------|---------|-----|---|---------|-+ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +---|---------|---|---|-----------|-----------------|---|---|------L----|-|-------+ | | | | | | | | | | | +-|-|-|---|-|---|-----|-|---+ | +---+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------|-|-----|-----------|-------|---+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | +-|-----------|-|---+ | +-------------|-----------------|---|-----|-|---|-|-----|---|-|---+ | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | +-------------|---|-------|-----|---------|---|-|-----|-----------+ | | | +-|-------|-------|-----|---+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-------|-|-------------|---|-+ | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | X | | | | | | | | | | | + | | | | | +---|-------|-----------------|---|-|-------------------|---------+ +-----|-------------|-----|-----|-----------------------|-|-------|---|-|---|-|-|-|-------+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +--B--|---------+ | | | | | | | | | | | | | | | | | | | | | | +-|-----------|---+ | | | | | | | | | | +-|---|---------+ | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | +---|-|-----------|---------|-------------|-------|-----|-|-|-----|---|-----------------------|-------|-|-------|-|-----|---|-----|-----|---|-----|-----|-|-----|---+ | +-|-|-|---+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | +-----------------------|-------|-|-|---------------|-------|-|-------+ | | | | | +-+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | +-----|-|-----------|-|---|-------------|---|-------|-----|---|-|---|-----|---------------|-----|-|-|-------|-|-------+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-------------|-|-|---------|---+ | | | | | | | | | | | | | +-|-----------------|-------+ | | | | | | | | | | | | | +---|---------|-----+ | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +---|-|-|---------|---------------------|---|-------|-----|-|-----|---+ +---|-------------|---|-------------------------|-|-|-----------|---|---------|-|-|---|-|---|---+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | +---|---------------------------------------|---------|-|---|-|---|-----|-----------|-|-----+ | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | +-|-|-----|-|-----------|-------------|-|-|---------|---|-----|-------|-----------|---|-------------+ | | | | | | | | | | | +-----|-|---+ | | +-|-|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-------|-|-------|-------------------------|---------|---|---------------------------------|---------------------|-|---|-|---|-----|-----|-------------|-|-----|-|-|---|---+ | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | +---------------------|---|-----------------|---------|-|---|---------------|---------|-------|---|---|-----------+ | + | | P | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | +-------------|-----|---|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | +-----|-|-|-|---|---|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | +-----|-----|-------|---|-----------------|-------------------------|---------------|-|---|-------|---|-----|---------|-+ | | | +-----|-|-|---|---------+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-|-|-----|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +---------|---+ | +---|-----|---|-|-------------|-----|-------|-|---------|---+ | +-----|-----|-----|-|-|-------------+ | +---------|-------|---|-|-|-----|-+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | +-+ | | | | | +---------|-----|-|-------|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | +-----------|-----------|-----|-----|---|-|-----|---------|-----|-|-|-------|-|-+ | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | +-------------------|-----|---|-|-|-------------|-----------|---|-----|---+ | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-|-------------------|---------|-|---------------|-----|-|-----|-------|-|-|-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | +-----|------H------+ | | | | | | | | | | +-|-----|---|-+ | | | +-+ | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----|---|---------+ | | +-|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | +-----|-----|---------+ | | | | | | | | | | | | | | | | | | | +---------------|-----|-|---|-------------|---|-----|-|-----|-----------------+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | V | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-|-------------|-------+ | | | | | | | | | | | | | | | | | | | | +---------------|-------|-+ | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | +-------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-+ | | | | | | | | +-------------|-------|---|-------+ | | | | +---|-|-|-----------|-|-------+ | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-----|-|-------------|---|---------------|-------|---|-------|---|-----|---|---------------------|---|---|-------------------|-----|---|-|-------|-------|-------|-+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | +---|-------------------|---------+ | | | | | | | +---+ | | +-|-+ | | | | | | | | | | | | +---|---------|-|-----+ | | +---------+ | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | +-------|-------------------+ +---------+ | | +-----|---|---|-+ | | | | | | | | | | +---------|---|---------|---|-+ | | | | | | | +-+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +-|-------|---|---+ +---------|-------------|-|-|-|-----|---|---|-|---------+ +-----|-----------------------------------|-----------|---|---|---|-|-------|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | + +---|-----|-|-------|-------|---------------------------------|---|---------|-|-----|---|-----------------------|---------------|-|-----|---+ | | | | | | | | | | | +-+ | | +-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | +-----|-|-|-----|---|---------|---|-----------------------|-------|-|-----------|-|-|----------E------|-------|---|---+ | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +-------|-----------|---------------------------|-|-|---|---|-----------|---|-----+ | | | | | | | | | | | | | +---|-----------|---------|---+ | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | +-|-|-------------------------------|-|-|-------|-|---|---------|---------------+ | +---------------|---|---------|---------------------|---+ | | | | +-+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | +---------------------------------|-|-|---|---|-|---|-|-------|-----------|-------|-----------|---|-------------|---|-----|---|---|-----|-|-------|---+ | +-+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-----+ +-----+ | | | | | | | | | | | | | | | | | | +---|-+ | | | | | | +-----|-------|---------|-----------|-----+ | +---|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +---------------------------|---+ | | | | | | | | | | +-------|-------|-----------|-------|---|-----------|-|---------------------|-----|-|---+ | +-------|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | +---|-----------|---|-|-----|-------|---|-|-----+ | | +-|---------|---|---------|-|---|-+ | | +-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-----------|-----|-------|---|---------------------------------|-------|---|-------|---------------|-----------|---+ | | | | | | | | | +-----|-+ | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +---------------|-|-|---------|-----------------------------|-----|-|-------|-|---|-|---|---|-------|---------------|-------|---|-|-|---------|---+ | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | +-|---|-+ +-------------------------------+ | | | | | +-----|---|-------|---------------|-------|-------|---+ | | | +-----|-|---|-----------|-|---------------|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-----------|-----|-|---|-|---|-|---+ | | | | | | | | | | | | | | +---|---|---|-|-|-+ | | | | | +---|---------|-|-----|-|---|---+ +-----|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | +---------------|---|-------|---|-|-----|---|-----------|---|-|---------|-------|-|-|---+ | | +---+ | | | | +-+ | +---|-------------+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | +-------+ +-------|-----------------------------|---+ +-|-----------|-------+ | | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +---+ | | +-----|---------|---------|---------------|-------|-----|-+ | | | | | +---------|-----|-------|-------------|---------|-|-----------|-----|---+ | +-|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +---|-----+ | | | | | | | | | | | | | | | +-|---|-----|---|-----------|-------+ +-----|---|-----------------|-----|-------|-|---------------|-------|---+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | +---|---|-|-----|---+ | | | | | +---------|---|-------------------------------------|-|-------------------------|-|---+ | | | | +-------|-|-------+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | | | +---------|---------------|-----------|---|-------------|---------------|-----|-----------|---------+ | +-+ | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-----|-----|---------+ | | | | +---+ | | | +-----------------------|-----------------+ | | | | | | | | | | | | | +---------|---+ +-----|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | +---|-------|---|-+ | | +-------|---------------|-----------------------|---|---|-------------|-|-----------+ | | | | +-------|---|-|-+ | | +---|-----|-----------|---|---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | | | | | | +-|-----------------------+ | +-----------|---------------+ | | | +-|-----|-|-------+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + +-----|-----------|-------|-------|---------------|-------|-------------+ | +---+ +-|-----|-------------------|-------------|-|-----|---+ +-+ | | | | | | | +---+ +-+ | | +---+ | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | | +---+ | | | | | | | +---------------|-----|-----------------------------------------|---------+ | | | +-------|-----------+ | | | | + | | | | | | | | | | | | | | | | | | | | | | | | | | | | + | +-----------|-------|---------------|-|-----|-------------------------------------|-------------------|-----------+ | +-----+ +-----------------------+ | | | | | | + | | | | | | | | | | | | | | | | | | | | | | | | + | +---------------------------|-----|-------------------------------|-------|-----------------|-------------+ +-------------|-------------+ +-------|---+ | | | + | | | | | | | | | | | | | | | | | | | | | | + +-------------------|-----------------------|-|-----|---------------------------------------------+ +---------|---------------------------+ | | | +---|-+ | | | | | + | | | | | | | | | | | | | | | | | | | | | | + +-------+ +-+ +---------+ +-------------+ +---------|---------------------------|-----|---------------|-----------+ +---|-+ + | | | | | | | | | | + +-------------------------------------+ +-----------------+ +-----|-------------------------------+ | | + | | | | | | | | + +-------------------------------------------------------------------------------------------+ +-+ +---------------+ +-+ + diff --git a/2017/day/19/problem.txt b/2017/day/19/problem.txt new file mode 100644 index 0000000..50ca463 --- /dev/null +++ b/2017/day/19/problem.txt @@ -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.) + diff --git a/2017/day/19/src/main.rs b/2017/day/19/src/main.rs new file mode 100644 index 0000000..213e6c3 --- /dev/null +++ b/2017/day/19/src/main.rs @@ -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, + width: usize, + height: usize, + stride: usize, +} + +impl Diagram { + fn new(data: Vec) -> 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()) +}