Back
Close

Fax machine

Statement

 Goal

An old compressed black and white fax transmission needs to be decompressed. The format of the compression is a series of numbers as such:

The first number is the width of the decompressed image.
The second number is the height of the decompressed image.
The starting color is black.
The third and remaining numbers are the number of pixels to draw from left to right, then top to bottom of the current color. After that number of pixels is filled then the color swaps.

The following fax

8
3
10 10 4

produces the following 8×3 output where "*" is black and " " (space) is white, and "|" is added as the left and right border

|********|
|** |
| ****|


This puzzle was inspired by https://www.codingame.com/training/expert/music-scores which has a very similar encoding system.

This encoding system is similar Modified Huffman Coding, which the earliest digital fax machines used. See https://en.wikipedia.org/wiki/Modified_Huffman_coding
Input
Line 1: Width
Line 2: Height
Line 3: Integers describing the compressed fax
Output
Height lines: rows with fax output of "*" (black) and " " (white) columns (surrounded by "|")
Constraints
1 ≤ Width, Height ≤ 100
Example
Input
8
3
10 10 4
Output
|********|
|**      |
|    ****|

Tags
Compression

Difficulty
Easy

Test cases
The Example Test
Input
8 3 10 10 4
Output
|********| |** | | ****|

The Example Validator
Input
8 3 10 9 5
Output
|********| |** | | *****|

Half Black half white Test
Input
32 6 93 99
Output
|********************************| |********************************| |***************************** | | | | | | |

Half Black half white Validator
Input
32 6 100 92
Output
|********************************| |********************************| |********************************| |**** | | | | |

Hello Test
Input
16 9 16 18 2 2 2 3 2 5 2 2 2 10 6 3 2 5 2 2 2 3 2 5 2 2 2 3 2 19 16
Output
|****************| | | | ** ** ** | | ** ** | | ****** ** | | ** ** ** | | ** ** ** | | | |****************|

Hello Validator
Input
16 9 1 15 18 2 2 2 3 2 5 2 2 2 10 6 3 2 5 2 2 2 3 2 5 2 2 2 3 2 34 1
Output
|* | |****************| |** ** *** ***| |** ** ********| |** *** ***| |** ** *** ***| |** ** *** ***| |****************| |*************** |

Heart Test
Input
23 7 6 4 3 4 11 6 1 6 11 11 13 9 16 6 18 4 20 2 10
Output
|****** *** ******| |***** * *****| |****** ******| |******* *******| |********* ********| |********** *********| |*********** **********|

Heart Validator
Input
23 7 11 2 20 4 18 6 15 9 13 11 11 6 1 6 11 4 3 4 6
Output
|*********** **********| |********** *********| |********* ********| |******* *******| |****** ******| |***** * *****| |****** *** ******|

Inverse Test
Input
23 7 0 6 4 3 4 11 6 1 6 11 11 13 9 16 6 18 4 20 2 10
Output
| **** **** | | ****** ****** | | *********** | | ********* | | ****** | | **** | | ** |

Inverse Validator
Input
23 7 0 11 2 20 4 18 6 15 9 13 11 11 6 1 6 11 4 3 4 6
Output
| ** | | **** | | ****** | | ********* | | *********** | | ****** ****** | | **** **** |

Solution language

Solution

Stub generator input