|
| 1 | +# Instructions |
| 2 | + |
| 3 | +A dot matrix is a two dimensional image made up of *dots* and *whitespace*. |
| 4 | +The dots form the intended image on the background of the whitespace. |
| 5 | + |
| 6 | +A dot matrix image can be stored and manipulated in memory as a two dimensional `Matrix`. |
| 7 | +In what follows, the "whitespace" in the matrices will be signified as `0` and the "dots" will be non-zero. |
| 8 | + |
| 9 | +## 1. Define the Exercism logo `Matrix` |
| 10 | + |
| 11 | +The `Matrix` looks as follows, with `0` as a whitespace and `1` as a dot: |
| 12 | + |
| 13 | +```julia |
| 14 | +[ |
| 15 | + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0; |
| 16 | + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; |
| 17 | + 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0; |
| 18 | + 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0; |
| 19 | + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; |
| 20 | + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1; |
| 21 | + 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0; |
| 22 | + 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0; |
| 23 | + 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0; |
| 24 | + 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; |
| 25 | + 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0; |
| 26 | +] |
| 27 | +``` |
| 28 | + |
| 29 | +If you "render" it, it looks like this: |
| 30 | + |
| 31 | +```julia |
| 32 | + XX XX |
| 33 | + X X |
| 34 | + X X X X |
| 35 | + X X X X X X |
| 36 | + X X |
| 37 | +X X |
| 38 | + X X X X |
| 39 | + X X X X |
| 40 | + X XX X |
| 41 | + X X |
| 42 | + XX XX |
| 43 | +``` |
| 44 | + |
| 45 | +## 2. Define functions that make the logo frown |
| 46 | + |
| 47 | +Define `frown!()` and `frown()` functions that take the Exercism logo `Matrix`. |
| 48 | +Return a `Matrix` with the smiling mouth changed to a frowning mouth. |
| 49 | + |
| 50 | +The resulting `Matrix` would render like this: |
| 51 | + |
| 52 | +```julia |
| 53 | + XX XX |
| 54 | + X X |
| 55 | + X X X X |
| 56 | + X X X X X X |
| 57 | + X X |
| 58 | +X X |
| 59 | + X XX X |
| 60 | + X X X X |
| 61 | + X X X X |
| 62 | + X X |
| 63 | + XX XX |
| 64 | +``` |
| 65 | + |
| 66 | +## 3. Put together a stickerwall |
| 67 | + |
| 68 | +Define the function `stickerwall()`, which takes the Exercism matrix as input. |
| 69 | +Return a `Matrix` of the dot matrix which renders as: |
| 70 | + |
| 71 | +```julia |
| 72 | + XX XX X XX XX |
| 73 | + X X X X X |
| 74 | + X X X X X X X X X |
| 75 | + X X X X X X X X X X X X X |
| 76 | + X X X X X |
| 77 | +X X X X X |
| 78 | + X X X X X X XX X |
| 79 | + X X X X X X X X X |
| 80 | + X XX X X X X X X |
| 81 | + X X X X X |
| 82 | + XX XX X XX XX |
| 83 | + X |
| 84 | +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| 85 | + X |
| 86 | + XX XX X XX XX |
| 87 | + X X X X X |
| 88 | + X X X X X X X X X |
| 89 | + X X X X X X X X X X X X X |
| 90 | + X X X X X |
| 91 | +X X X X X |
| 92 | + X XX X X X X X X |
| 93 | + X X X X X X X X X |
| 94 | + X X X X X X XX X |
| 95 | + X X X X X |
| 96 | + XX XX X XX XX |
| 97 | +``` |
| 98 | + |
| 99 | +## 4. Change dots to column pixel counts |
| 100 | + |
| 101 | +We aren't limited to just using `1` as the dot, so we could encode other useful information if desired. |
| 102 | +Define the function `colpixelcount()` which takes *any* dot matrix with `1` dots as input. |
| 103 | +Return a dot matrix of the same size, with the dots in each column being the number of dots in that column. |
| 104 | + |
| 105 | +With the Exercism logo `Matrix` as input, the output is a `Matrix` as follows: |
| 106 | + |
| 107 | +```julia |
| 108 | +[ |
| 109 | + 0 0 2 2 0 0 0 0 0 0 0 0 0 0 2 2 0 0; |
| 110 | + 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0; |
| 111 | + 0 8 0 0 0 1 0 0 0 0 0 0 1 0 0 0 8 0; |
| 112 | + 0 8 0 0 1 0 2 0 0 0 0 2 0 1 0 0 8 0; |
| 113 | + 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0; |
| 114 | + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1; |
| 115 | + 0 8 0 0 0 0 2 0 0 0 0 2 0 0 0 0 8 0; |
| 116 | + 0 8 0 0 0 0 0 1 0 0 1 0 0 0 0 0 8 0; |
| 117 | + 0 8 0 0 0 0 0 0 1 1 0 0 0 0 0 0 8 0; |
| 118 | + 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0; |
| 119 | + 0 0 2 2 0 0 0 0 0 0 0 0 0 0 2 2 0 0; |
| 120 | +] |
| 121 | +``` |
| 122 | + |
| 123 | +## 5. Render a dot matrix |
| 124 | + |
| 125 | +Rather than just talk about rendering our creations, we would like to actually be able to do that for easy viewing. |
| 126 | +Define the function `render()` which takes a dot matrix as input. |
| 127 | +Return a string with dots rendered as `'X'`, the `0`s as `' '`, and newlines connecting each row. |
| 128 | + |
| 129 | +```julia-repl |
| 130 | +julia> render(E) |
| 131 | +" XX XX \n X X \n X X X X \n X X X X X X \n X X \nX X\n X X X X \n X X X X \n X XX X \n X X \n XX XX " |
| 132 | +``` |
| 133 | + |
| 134 | +When printed, this should render the Exercism Matrix as expected. |
| 135 | + |
| 136 | +```julia-repl |
| 137 | +julia> print(render(E)) |
| 138 | + XX XX |
| 139 | + X X |
| 140 | + X X X X |
| 141 | + X X X X X X |
| 142 | + X X |
| 143 | +X X |
| 144 | + X X X X |
| 145 | + X X X X |
| 146 | + X XX X |
| 147 | + X X |
| 148 | + XX XX |
| 149 | +``` |
| 150 | + |
| 151 | +This should also work with "dots" that are different than `1`: |
| 152 | + |
| 153 | +```julia-repl |
| 154 | +julia> print(render(colpixelcount(E))) |
| 155 | + XX XX |
| 156 | + X X |
| 157 | + X X X X |
| 158 | + X X X X X X |
| 159 | + X X |
| 160 | +X X |
| 161 | + X X X X |
| 162 | + X X X X |
| 163 | + X XX X |
| 164 | + X X |
| 165 | + XX XX |
| 166 | +``` |
0 commit comments