30
5
Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro.
I am an evil farmer, and to drive up the price of wheat in my area, I've decided to burn the fields of all the farmers around me. I would really like to see the fields go up in flames (so I can use my evil laugh and rub my hands together with glee), but I also don't want to be caught watching, so I need you to simulate the field being incinerated for me.
Your Task:
Write a program or function that takes as input a field, and returns the stages of it burning until the entire field is ash. A specific section of the field that is on fire is represented by an integer representing the intensity of the flame. A fire starts at "1" and moves on to "2" and then "3", and so on. Once a fire reaches "4", it catches any directly (not diagonally) adjacent areas that are flammable on fire. Once it reaches "8", it burns out on the next iteration, and turns into ash, represented by an "A". When an area has not yet been touched by fire, it is represented by a "0". For example, if the field looks like this:
100
000
Your program should output this:
100
000
200
000
300
000
410
100
520
200
630
300
741
410
852
520
A63
630
A74
741
A85
852
AA6
A63
AA7
A74
AA8
A85
AAA
AA6
AAA
AA7
AAA
AA8
AAA
AAA
If you wish, you may replace the above symbols with any set of symbols you choose, as long as they are consistent and distinct from each other.
Input:
The starting position of the field, in any standard form, such as a newlined-delimated string as above.
Output:
The field in every iteration as it burns, either as an array, or as a string delimited by some character.
Test Cases:
0301
000A
555
|
v
0301
000A
555
1412
010A
666
2523
020A
777
3634
030A
888
4745
141A
AAA
5856
252A
AAA
6A67
363A
AAA
7A78
474A
AAA
8A8A
585A
AAA
AAAA
6A6A
AAA
AAAA
7A7A
AAA
AAAA
8A8A
AAA
AAAA
AAAA
AAA
Scoring:
This is code-golf, lowest score in bytes wins!
Related – H.PWiz – 2017-08-08T02:03:16.463
Certainly related, but not a duplicate IMO. – Gryphon – 2017-08-08T02:04:33.807
1How much can the shape vary? Are the non-rectangular parts always "holes" on the right edge, or can there be spaces in the field? – PurkkaKoodari – 2017-08-08T08:08:50.430
3So something that hits 4 starts a fire in adjacent squares, but something that starts out at 4 or higher doesn't? That's not very realistic. – laszlok – 2017-08-08T08:13:40.290
So the field is not guaranteed to be rectangular ... Can we at least assume that it has no gaps? – Titus – 2017-08-08T09:25:43.983
14"Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro." -> Starts with "I'm an evil farmer [who wants to do evil stuff]." Very clever. No one will relate the burning fields to you now. – J_F_B_M – 2017-08-08T10:09:43.853
3Is it possible for initial ash to separate the field in two, so that part of it will never burn? – aschepler – 2017-08-08T10:58:54.900
So fires more intense than 4 don't spread? Strange. – aschepler – 2017-08-08T11:01:45.960
@laszlok, I know, but it was a mistake in the spec that wasn't caught in the sandbox, and now I have answers, so I can't change it. – Gryphon – 2017-08-08T11:15:28.440
@Titus, yes you may. – Gryphon – 2017-08-08T11:15:49.663
9If the fire not spreading above 4 is too upsetting, imagine that 1-4 is the fire gaining intensity and 5-A represents it burning out. – Jeremy Weirich – 2017-08-08T12:32:56.577
@Pietu1998, I'm sorry I didn't see your comment up there previously. Non-rectangular sections are always gaps on the right side. – Gryphon – 2017-08-08T23:46:17.233
May we assume the field is at least 3×3? I.e. require smaller fields to be given with surrounding empty slots until at least 3×3 in size? – Adám – 2017-08-09T07:07:20.310
1@Adám, sure you can. – Gryphon – 2017-08-09T12:49:42.687
For "The field in every iteration as it burns", can I go beyond the time when everything that would burn has burned to
A
sh? (as long as the code theoretically handles arbitrarily large fields) Or do I need to detect when no more changes will be made and stop showing new iterations then? – Mark S. – 2017-08-13T21:24:52.0631@MarkS., you need to stop showing iterations when no changes will be made. – Gryphon – 2017-08-16T11:53:19.523