aoc-2021-rust

Advent of Code 2021 Solutions in Rust
git clone https://git.sinitax.com/sinitax/aoc-2021-rust
Log | Files | Refs | README | sfeed.txt

part2 (1189B)


      1--- Part Two ---
      2
      3The crabs don't seem interested in your proposed solution. Perhaps you misunderstand crab
      4engineering?
      5
      6As it turns out, crab submarine engines don't burn fuel at a constant rate. Instead, each change of
      71 step in horizontal position costs 1 more unit of fuel than the last: the first step costs 1, the
      8second step costs 2, the third step costs 3, and so on.
      9
     10As each crab moves, moving further becomes more expensive. This changes the best horizontal position
     11to align them all on; in the example above, this becomes 5:
     12
     13
     14 - Move from 16 to 5: 66 fuel
     15
     16 - Move from 1 to 5: 10 fuel
     17
     18 - Move from 2 to 5: 6 fuel
     19
     20 - Move from 0 to 5: 15 fuel
     21
     22 - Move from 4 to 5: 1 fuel
     23
     24 - Move from 2 to 5: 6 fuel
     25
     26 - Move from 7 to 5: 3 fuel
     27
     28 - Move from 1 to 5: 10 fuel
     29
     30 - Move from 2 to 5: 6 fuel
     31
     32 - Move from 14 to 5: 45 fuel
     33
     34
     35This costs a total of 168 fuel. This is the new cheapest possible outcome; the old alignment
     36position (2) now costs 206 fuel instead.
     37
     38Determine the horizontal position that the crabs can align to using the least fuel possible so they
     39can make you an escape route! How much fuel must they spend to align to that position?
     40
     41