From 705d2d01eabfc4bcfd32303637813406a53b5881 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Thu, 15 Dec 2022 21:08:51 +0000 Subject: day14 --- input/day14.txt | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++ input/day14_ex.txt | 2 + src/day14.rs | 125 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 + 4 files changed, 304 insertions(+) create mode 100644 input/day14.txt create mode 100644 input/day14_ex.txt create mode 100644 src/day14.rs diff --git a/input/day14.txt b/input/day14.txt new file mode 100644 index 0000000..155625a --- /dev/null +++ b/input/day14.txt @@ -0,0 +1,175 @@ +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +538,67 -> 542,67 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +527,148 -> 532,148 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +523,46 -> 527,46 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +548,104 -> 548,105 -> 559,105 -> 559,104 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +517,46 -> 521,46 +514,152 -> 519,152 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +541,64 -> 545,64 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +548,104 -> 548,105 -> 559,105 -> 559,104 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +514,40 -> 518,40 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +510,140 -> 510,141 -> 521,141 -> 521,140 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +529,89 -> 534,89 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +521,85 -> 526,85 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +535,58 -> 539,58 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +526,67 -> 530,67 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +532,67 -> 536,67 +544,67 -> 548,67 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +538,61 -> 542,61 +525,87 -> 530,87 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +513,148 -> 518,148 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +508,44 -> 512,44 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +528,152 -> 533,152 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +515,89 -> 520,89 +521,152 -> 526,152 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +511,46 -> 515,46 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +507,152 -> 512,152 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +532,87 -> 537,87 +531,150 -> 536,150 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +515,123 -> 531,123 -> 531,122 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +511,42 -> 515,42 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +528,85 -> 533,85 +505,42 -> 509,42 +495,15 -> 495,16 -> 501,16 -> 501,15 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +524,150 -> 529,150 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +532,61 -> 536,61 +536,89 -> 541,89 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +520,148 -> 525,148 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +535,152 -> 540,152 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +502,44 -> 506,44 +548,104 -> 548,105 -> 559,105 -> 559,104 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +514,44 -> 518,44 +517,150 -> 522,150 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +495,15 -> 495,16 -> 501,16 -> 501,15 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +535,64 -> 539,64 +515,123 -> 531,123 -> 531,122 +517,42 -> 521,42 +520,44 -> 524,44 +510,150 -> 515,150 +529,64 -> 533,64 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +499,46 -> 503,46 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +527,49 -> 527,51 -> 523,51 -> 523,55 -> 536,55 -> 536,51 -> 531,51 -> 531,49 +510,140 -> 510,141 -> 521,141 -> 521,140 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +522,89 -> 527,89 +505,46 -> 509,46 +508,40 -> 512,40 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +523,146 -> 528,146 +518,87 -> 523,87 +495,15 -> 495,16 -> 501,16 -> 501,15 +516,146 -> 521,146 +511,38 -> 515,38 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +510,140 -> 510,141 -> 521,141 -> 521,140 +499,19 -> 499,21 -> 497,21 -> 497,24 -> 508,24 -> 508,21 -> 505,21 -> 505,19 +522,80 -> 522,75 -> 522,80 -> 524,80 -> 524,71 -> 524,80 -> 526,80 -> 526,77 -> 526,80 +533,102 -> 533,93 -> 533,102 -> 535,102 -> 535,95 -> 535,102 -> 537,102 -> 537,99 -> 537,102 -> 539,102 -> 539,97 -> 539,102 -> 541,102 -> 541,92 -> 541,102 -> 543,102 -> 543,94 -> 543,102 -> 545,102 -> 545,99 -> 545,102 -> 547,102 -> 547,95 -> 547,102 -> 549,102 -> 549,101 -> 549,102 +508,27 -> 508,29 -> 503,29 -> 503,35 -> 512,35 -> 512,29 -> 510,29 -> 510,27 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 +495,136 -> 495,127 -> 495,136 -> 497,136 -> 497,135 -> 497,136 -> 499,136 -> 499,129 -> 499,136 -> 501,136 -> 501,133 -> 501,136 -> 503,136 -> 503,135 -> 503,136 -> 505,136 -> 505,135 -> 505,136 -> 507,136 -> 507,130 -> 507,136 -> 509,136 -> 509,130 -> 509,136 -> 511,136 -> 511,127 -> 511,136 -> 513,136 -> 513,127 -> 513,136 +524,83 -> 529,83 +491,155 -> 491,157 -> 490,157 -> 490,160 -> 501,160 -> 501,157 -> 497,157 -> 497,155 +519,144 -> 524,144 +506,118 -> 506,115 -> 506,118 -> 508,118 -> 508,112 -> 508,118 -> 510,118 -> 510,115 -> 510,118 -> 512,118 -> 512,114 -> 512,118 -> 514,118 -> 514,108 -> 514,118 -> 516,118 -> 516,110 -> 516,118 -> 518,118 -> 518,116 -> 518,118 -> 520,118 -> 520,115 -> 520,118 \ No newline at end of file diff --git a/input/day14_ex.txt b/input/day14_ex.txt new file mode 100644 index 0000000..1926028 --- /dev/null +++ b/input/day14_ex.txt @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 \ No newline at end of file diff --git a/src/day14.rs b/src/day14.rs new file mode 100644 index 0000000..97c06fe --- /dev/null +++ b/src/day14.rs @@ -0,0 +1,125 @@ +const AIR: char = '.'; +const ROCK: char = '#'; +const SANDSPAWN: char = '+'; +const MOVING_SAND: char = '*'; +const STUCK_SAND: char = 'o'; + +pub fn run(input: String) { + // line segments + let ls: Vec> = input.lines().map(|line| { + let cornersstr = line.split("->"); + cornersstr.map(|cornerstr| { + let (xs,ys) = cornerstr.split_once(",").expect("coordinate didn't have a , in it!"); + (xs.trim().parse::().expect("xs wasn't a i32!"), ys.trim().parse::().expect("ys wasn't a i32!")) + }).collect() + }).collect(); + // Find our grid bounds,no need to have a 590 cell wide grid... or maybe you just should? idk. + // yeah you'll need a buffer to the left for the sand to fall off of, otherwise it hits the side and that's no good. + // let ((max_x, max_y),(min_x,min_y)) = ls.iter().flatten().fold(((0,0),(usize::MAX,usize::MAX)), |((max_x,max_y),(min_x,min_y)),(x,y)| { + // ((x.max(*max_x), y.max(max_y)), + // (x.min(min_x), y.min(min_y))) + // }); + let (max_x, max_y) = ls.iter().flatten().fold((0 as i32,0 as i32), |(max_x,max_y),(x,y)| { + (*x.max(&max_x),*y.max(&max_y)) + }); + // +2, give a row/col of buffer + // Actually x2, in case we have a pyramid of sand... + let mut grid: Vec> = (0..=(max_y+2)).map(|_| { + //(0..(max_x+2)).map(|_| { + (0..(max_x*2+2)).map(|_| { + AIR + }).collect() + }).collect(); + + // pt2; add the floor + let floor: usize = (max_y+2).try_into().unwrap(); + for i in 0..(max_x*2+2) { + grid[floor][i as usize] = '#'; + } + + for l in ls { + for cs in l[..].windows(2) { + if cs.len() != 2 { panic!("window function failed???") } + let (c1, c2) = (cs[0], cs[1]); + let xd = c1.0 - c2.0; + let yd = c1.1 - c2.1; + if xd != 0 && yd != 0 { panic!("diagonal line segment???") } + if xd != 0 { + let y = c1.1 as usize; + for x in (c1.0.min(c2.0))..=(c1.0.max(c2.0)) { + grid[y][x as usize] = ROCK; + } + } else if yd != 0 { + let x = c1.0 as usize; + for y in (c1.1.min(c2.1))..=(c1.1.max(c2.1)) { + grid[y as usize][x] = ROCK; + } + } else { + panic!("0 length line segment???") + } + } + } + let sandspawn = (500,0); + let mut sand = sandspawn; + let mut ix = 0; + + 'lp: loop { + if let Some(np) = mov(&grid,&sand) { + // if np.1 >= max_y.try_into().expect("max_y couldn't fit a usize???") { + // println!("sand reached the end!"); + // break 'lp; + // } + sand = np; + } else { + // Convert the sand to a stuck sand + grid[sand.1][sand.0] = STUCK_SAND; + + if sand == sandspawn { + // If we couldn't move, and we're still on the spawn, then we're done! + break 'lp; + } else { + // Otherwise, spawn a new sand + sand = sandspawn; + } + } + + ix += 1; + if ix > 1_000_000_000 { + eprint!("not getting out of here!"); + break 'lp; + } + } + + // Count the stuck sand + //print(&grid, &sandspawn, &sand); + let c_stuck_sand = grid.into_iter().flatten().filter(|ch| {*ch == STUCK_SAND}).count(); + println!("Day 14: {}", c_stuck_sand); +} + +fn mov(grid: &Vec>, sand: &(usize,usize)) -> Option<(usize,usize)> { + if grid[sand.1+1][sand.0] == AIR { + Some((sand.0,sand.1+1)) + } else if grid[sand.1+1][sand.0-1] == AIR { + Some((sand.0-1,sand.1+1)) + } else if grid[sand.1+1][sand.0+1] == AIR { + Some((sand.0+1,sand.1+1)) + } else { + None + } +} + +fn print(grid: &Vec>, sandspawn: &(usize,usize), sand: &(usize,usize)) { + for (y, line) in grid.into_iter().enumerate() { + for (x, ch) in line.into_iter().enumerate().skip(480) { + let pt = (x,y); + if sand == &pt { + print!("{}", MOVING_SAND); + } else if sandspawn == &pt { + print!("{}", SANDSPAWN); + } else { + print!("{}", ch); + } + } + print!("\n"); + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 0b427f1..38ed88d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod day10; mod day11; mod day12; mod day13; +mod day14; fn main() { day1::run(fs::read_to_string("input/day1.txt").expect("Failed to read input file!")); @@ -30,4 +31,5 @@ fn main() { day11::run(fs::read_to_string("input/day11.txt").expect("Failed to read input file!")); day12::run(fs::read_to_string("input/day12.txt").expect("Failed to read input file!")); day13::run(fs::read_to_string("input/day13.txt").expect("Failed to read input file!")); + day14::run(fs::read_to_string("input/day14.txt").expect("Failed to read input file!")); } -- cgit v1.2.3-ZIG