Robert Mion

Posted on

# Pyroclastic Flow

## Part 1

1. It's Tetris, broh!
2. The work it will take
3. Representing the tetrominoes
4. It's just too much to manage

### It's Tetris, broh!

This is gonna be so much fun!

He thought.

I'm pumped to solve this and build a simulator for it!

He said to himself.

It all seems doable.

He reassured himself.

### The work it will take

I had two days to ruminate on this puzzle before starting this article or writing any code.

Each of the strands of thought led me to one conclusion:

• This is gonna be a lot of work, and that work is building this game

Work like:

• Lots of conditions
• Lots of nested arrays
• Lots of array accessing to check for collisions
• Lots of array manipulation to cycle through rocks and update the game board
• Perhaps some modulo to cycle through the puzzle input

I am prepared to attempt the work.
I'm skeptical of getting it to work as desired.
I foresee writing lots of code.
Most of it will be deleted.
But all of it is worth getting practice, making mistakes, and learning.

### Representing the tetrominoes

• I feel like I need a table-like structure
• Nested arrays feels like the way to go

Here's my first draft:

let rocks = [
[
['#','#','#','#']
],
[
['.','#','.'],
['#','#','#'],
['.','#','.']
],
[
['.','.','#'],
['.','.','#'],
['#','#','#']
],
[
['#'],
['#'],
['#'],
['#']
],
[
['#','#'],
['#','#']
]
]
• An array with five nested arrays
• One for each tetromino
• And each tetromino uses sibling arrays of strings
• Where each array is a row and each item is a column

I sense that I'll have to adjust this as I start writing the logic for the game.

### It's just too much to manage

I started writing an algorithm.

I got as far as:

• Representing the chamber as a nested 9-element array
• Adding rows at the start of the chamber
• Placing the next rock three cells from the left edge of the top of the chamber
• Making a copy of the chamber for use during movement
• Writing the initial steps that happen if the jet move the rock to the right: is the rock gonna hit the wall?

This already feels like a lot of state to manage.

And an avalanche of conditions to check.

And it's just not fun. At all.

So, I hereby throw in the towel way earlier than I had hoped for this challenge.

Maybe I'll come back to it one day and work up the patience, grit and spirit to attempt it fully.

But for now, I'm more excited to skip it in hopes that Day 18 will present a different but less gauntlet-like puzzle.