In this challenge, I have a field of avocados which I'd like to juice as quickly and completely as possible. Can you write a program or function to help me work out how to juice all the avocados perfectly?
As input, you'll get the avocados as an
m square grid, where
m is an integer between 3 and 6. Each square contains exactly one avocado. Avocados have several stages of juiciness:
Stage 1: The avocado has not been juiced at all.
Stage 2: The avocado has been partially juiced.
Stage 3: The avocado has been completely juiced.
Stage 4: The avocado has exploded due to over-juicing.
When you use a juicing tool, the avocados in that juicing tool's area of effect move to the next stage. Exploding avocados have a lot of force and will destroy the entire avocado field, so make sure none of the avocados explode!
Here is an example of a grid of avocados. In these examples, I've used the coordinate
0,0 for the bottom-left corner, and the coordinate
2,2 for the top-right corner, although you can adjust the coordinate system to suit your language.
112 221 231
The goal is to make all the avocados perfectly juiced (i.e. stage 3). To achieve this you have three different juicing tools in your possession. Each juicing tool have a different area of effect, but they all increase the juiciness of affected avocados by 1.
Here are all the tools you have at your disposal. You use the juicers by specifying the first letter of the tool, then the coordinates which you want to juice. For example, to use the Slicer on square
5,2, you would output
Slicer: Juices the target coordinate and the avocado on either side.
112 112 112 221 --> XXX --> 332 231 231 231
Grater: Juices the target coordinate and the avocado above and below.
112 1X2 122 221 --> 2X1 --> 231 --> kaboom! 231 2X1 241
Rocket Launcher: Juices the target coordinate and all adjacent avocados.
112 1X2 122 221 --> XXX --> 332 221 2X1 231
Sample Inputs and Outputs
323 212 323 G 1,1 S 1,1 3312 3121 1213 2133 R 0,0 R 1,1 R 2,2 R 3,3 22322 22222 22222 33233 33333 G 0,3 G 1,3 G 2,2 G 3,3 G 4,3 222332 333221 222332 333222 222333 333222 S 1,5 S 1,3 S 1,1 S 4,5 S 4,3 S 4,1 G 5,4