The tile floor in the lobby is meant to be a living art exhibit. Every day, the tiles are all flipped according to the following rules:

Here, tiles immediately adjacent means the six tiles directly touching the tile in question.

The rules are applied simultaneously to every tile; put another way, it is first determined which tiles need to be flipped, then they are all flipped at the same time.

In the above example, the number of black tiles that are facing up after the given number of days has passed is as follows:

Day 1: 15
Day 2: 12
Day 3: 25
Day 4: 14
Day 5: 23
Day 6: 28
Day 7: 41
Day 8: 37
Day 9: 49
Day 10: 37

Day 20: 132
Day 30: 259
Day 40: 406
Day 50: 566
Day 60: 788
Day 70: 1106
Day 80: 1373
Day 90: 1844
Day 100: 2208

After executing this process a total of 100 times, there would be 2208 black tiles facing up.

Assignment

How many tiles will be black after \(n\) days? Determine this in the following way:

This static function must be located in the class Submission.

Example

In this interactive session we assume the text file tiles.txt1 to be located in the current directory.

> Submission.blackTiles("tiles.txt", 0)
10
> Submission.blackTiles("tiles.txt", 1)
15
> Submission.blackTiles("tiles.txt", 2)
12
> Submission.blackTiles("tiles.txt", 3)
25
> Submission.blackTiles("tiles.txt", 4)
14
> Submission.blackTiles("tiles.txt", 5)
23
> Submission.blackTiles("tiles.txt", 6)
28
> Submission.blackTiles("tiles.txt", 7)
41
> Submission.blackTiles("tiles.txt", 8)
37
> Submission.blackTiles("tiles.txt", 9)
49
> Submission.blackTiles("tiles.txt", 10)
37
> Submission.blackTiles("tiles.txt", 20)
132
> Submission.blackTiles("tiles.txt", 30)
259
> Submission.blackTiles("tiles.txt", 40)
406
> Submission.blackTiles("tiles.txt", 50)
566
> Submission.blackTiles("tiles.txt", 60)
788
> Submission.blackTiles("tiles.txt", 70)
1106
> Submission.blackTiles("tiles.txt", 80)
1373
> Submission.blackTiles("tiles.txt", 90)
1844
> Submission.blackTiles("tiles.txt", 100)
2208

Epilogue

Marcel B (@mrclbschff2) animated his solution for this assignment.