Skip to content

Commit 7955cee

Browse files
authored
modify concept exercise exercism-matrix (#997)
* modify concept exercise exercism-matrix * adjust hints.md
1 parent 0154ba0 commit 7955cee

File tree

12 files changed

+634
-247
lines changed

12 files changed

+634
-247
lines changed

config.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@
392392
],
393393
"status": "wip"
394394
},
395+
{
396+
"slug": "exercism-matrix",
397+
"name": "Exercism Matrix",
398+
"uuid": "36cbda04-3921-4491-9ec6-76951f00aa00",
399+
"concepts": [
400+
"multi-dimensional-arrays"
401+
],
402+
"prerequisites": [
403+
"function-composition"
404+
],
405+
"status": "wip"
406+
},
395407
{
396408
"slug": "old-elyses-enchantments",
397409
"name": "Old Elyse's Enchantments",
@@ -456,14 +468,6 @@
456468
"prerequisites": [],
457469
"status": "deprecated"
458470
},
459-
{
460-
"slug": "old-exercism-matrix",
461-
"name": "Old The Exercism Matrix",
462-
"uuid": "36cbda04-3921-4491-9ec6-76951f00aa00",
463-
"concepts": [],
464-
"prerequisites": [],
465-
"status": "deprecated"
466-
},
467471
{
468472
"slug": "old-emoji-times",
469473
"name": "Old 🕑🕤🕗",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Hints
2+
3+
The introduction contains most of what is needed for this exercise.
4+
5+
## 1. Define the Exercism logo `Matrix`
6+
7+
- Get creative! However, you can also simply copy and paste from the instructions.
8+
9+
## 2. Define functions that make the logo frown
10+
11+
- Remember that functions ending in `!` mutate the input (modify in-place), while others do not.
12+
- `frown!` can be done via assignment of specific elements, or (less efficiently) by swapping two rows.
13+
- `frown` is going to be very similar to `frown!`, just returning a copy of the input matrix.
14+
15+
## 3. Put together a stickerwall
16+
17+
- Use your `frown()` function.
18+
- The `vcat()` and `hcat()` functions, or their equivalents, are your friends here.
19+
- The `ones()` and `zeros()` functions can also be quite useful.
20+
21+
## 4. Change dots to column pixel counts
22+
23+
- Broadcasting is a great way to do this concisely.
24+
- To broadcast, you'll need a vector with the column dot counts.
25+
- To get a vector with column dot count, you can apply a function to the `Matrix`.
26+
27+
## 5. Render a dot matrix
28+
29+
- Using `eachrow()` to loop may work well here.
30+
- The function `join()` can also help.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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

Comments
 (0)