Skip to content

Commit 8c5e45e

Browse files
Sync exercise docs (exercism#429)
zebra-puzzle example solution updated with hobbies [no important files changed]
1 parent a71b94a commit 8c5e45e

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed

exercises/practice/affine-cipher/.docs/instructions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ E(x) = (ai + b) mod m
1818

1919
Where:
2020

21-
- `i` is the letter's index from `0` to the length of the alphabet - 1
21+
- `i` is the letter's index from `0` to the length of the alphabet - 1.
2222
- `m` is the length of the alphabet.
2323
For the Roman alphabet `m` is `26`.
24-
- `a` and `b` are integers which make the encryption key
24+
- `a` and `b` are integers which make up the encryption key.
2525

2626
Values `a` and `m` must be _coprime_ (or, _relatively prime_) for automatic decryption to succeed, i.e., they have number `1` as their only common factor (more information can be found in the [Wikipedia article about coprime integers][coprime-integers]).
2727
In case `a` is not coprime to `m`, your program should indicate that this is an error.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
# Instructions
22

3-
Compute Pascal's triangle up to a given number of rows.
3+
Your task is to output the first N rows of Pascal's triangle.
44

5-
In Pascal's Triangle each number is computed by adding the numbers to the right and left of the current position in the previous row.
5+
[Pascal's triangle][wikipedia] is a triangular array of positive integers.
6+
7+
In Pascal's triangle, the number of values in a row is equal to its row number (which starts at one).
8+
Therefore, the first row has one value, the second row has two values, and so on.
9+
10+
The first (topmost) row has a single value: `1`.
11+
Subsequent rows' values are computed by adding the numbers directly to the right and left of the current position in the previous row.
12+
13+
If the previous row does _not_ have a value to the left or right of the current position (which only happens for the leftmost and rightmost positions), treat that position's value as zero (effectively "ignoring" it in the summation).
14+
15+
## Example
16+
17+
Let's look at the first 5 rows of Pascal's Triangle:
618

719
```text
820
1
921
1 1
1022
1 2 1
1123
1 3 3 1
1224
1 4 6 4 1
13-
# ... etc
1425
```
26+
27+
The topmost row has one value, which is `1`.
28+
29+
The leftmost and rightmost values have only one preceding position to consider, which is the position to its right respectively to its left.
30+
With the topmost value being `1`, it follows from this that all the leftmost and rightmost values are also `1`.
31+
32+
The other values all have two positions to consider.
33+
For example, the fifth row's (`1 4 6 4 1`) middle value is `6`, as the values to its left and right in the preceding row are `3` and `3`:
34+
35+
[wikipedia]: https://en.wikipedia.org/wiki/Pascal%27s_triangle
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Introduction
2+
3+
With the weather being great, you're not looking forward to spending an hour in a classroom.
4+
Annoyed, you enter the class room, where you notice a strangely satisfying triangle shape on the blackboard.
5+
Whilst waiting for your math teacher to arrive, you can't help but notice some patterns in the triangle: the outer values are all ones, each subsequent row has one more value than its previous row and the triangle is symmetrical.
6+
Weird!
7+
8+
Not long after you sit down, your teacher enters the room and explains that this triangle is the famous [Pascal's triangle][wikipedia].
9+
10+
Over the next hour, your teacher reveals some amazing things hidden in this triangle:
11+
12+
- It can be used to compute how many ways you can pick K elements from N values.
13+
- It contains the Fibonacci sequence.
14+
- If you color odd and even numbers differently, you get a beautiful pattern called the [Sierpiński triangle][wikipedia-sierpinski-triangle].
15+
16+
The teacher implores you and your classmates to lookup other uses, and assures you that there are lots more!
17+
At that moment, the school bell rings.
18+
You realize that for the past hour, you were completely absorbed in learning about Pascal's triangle.
19+
You quickly grab your laptop from your bag and go outside, ready to enjoy both the sunshine _and_ the wonders of Pascal's triangle.
20+
21+
[wikipedia]: https://en.wikipedia.org/wiki/Pascal%27s_triangle
22+
[wikipedia-sierpinski-triangle]: https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle

exercises/practice/zebra-puzzle/.docs/instructions.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ The following 15 statements are all known to be true:
1212
1. There are five houses.
1313
2. The Englishman lives in the red house.
1414
3. The Spaniard owns the dog.
15-
4. Coffee is drunk in the green house.
15+
4. The person in the green house drinks coffee.
1616
5. The Ukrainian drinks tea.
1717
6. The green house is immediately to the right of the ivory house.
18-
7. The Old Gold smoker owns snails.
19-
8. Kools are smoked in the yellow house.
20-
9. Milk is drunk in the middle house.
18+
7. The snail owner likes to go dancing.
19+
8. The person in the yellow house is a painter.
20+
9. The person in the middle house drinks milk.
2121
10. The Norwegian lives in the first house.
22-
11. The man who smokes Chesterfields lives in the house next to the man with the fox.
23-
12. Kools are smoked in the house next to the house where the horse is kept.
24-
13. The Lucky Strike smoker drinks orange juice.
25-
14. The Japanese smokes Parliaments.
22+
11. The person who enjoys reading lives in the house next to the person with the fox.
23+
12. The painter's house is next to the house with the horse.
24+
13. The person who plays football drinks orange juice.
25+
14. The Japanese person plays chess.
2626
15. The Norwegian lives next to the blue house.
2727

28-
Additionally, each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and smoke different brands of cigarettes.
28+
Additionally, each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and engage in different hobbies.
2929

3030
~~~~exercism/note
3131
There are 24 billion (5!⁵ = 24,883,200,000) possible solutions, so try ruling out as many solutions as possible.

exercises/practice/zebra-puzzle/.docs/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Introduction
22

33
The Zebra Puzzle is a famous logic puzzle in which there are five houses, each painted a different color.
4-
The houses have different inhabitants, who have different nationalities, own different pets, drink different beverages and smoke different brands of cigarettes.
4+
The houses have different inhabitants, who have different nationalities, own different pets, drink different beverages and enjoy different hobbies.
55

66
To help you solve the puzzle, you're given 15 statements describing the solution.
77
However, only by combining the information in _all_ statements will you be able to find the solution to the puzzle.

exercises/practice/zebra-puzzle/.meta/example.el

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
(defvar houses-by-number nil)
2424

2525
(cl-defstruct house
26-
number color owner pet drink smokes)
26+
number color owner pet drink hobby)
2727

2828
(setq all-houses
2929
(cl-loop for n in '(1 2 3 4 5)
3030
append (cl-loop for c in '(red green ivory yellow blue)
3131
append (cl-loop for o in '(Englishman Spaniard Ukrainian Norwegian Japanese)
3232
append (cl-loop for p in '(dog snails fox horse zebra)
3333
append (cl-loop for d in '(coffee tea milk orange-juice water)
34-
append (cl-loop for s in '(Old-Gold Kools Chesterfields Lucky-Strike Parliaments)
35-
collect (make-house :number n :color c :owner o :pet p :drink d :smokes s))))))))
34+
append (cl-loop for e in '(dancing painting reading football chess)
35+
collect (make-house :number n :color c :owner o :pet p :drink d :hobby e))))))))
3636

3737
(setq house-constraints
3838
(list
@@ -44,18 +44,18 @@
4444
(equal (house-color h) 'green)))
4545
(lambda (h) (equal (equal (house-owner h) 'Ukrainian)
4646
(equal (house-drink h) 'tea)))
47-
(lambda (h) (equal (equal (house-smokes h) 'Old-Gold)
47+
(lambda (h) (equal (equal (house-hobby h) 'dancing)
4848
(equal (house-pet h) 'snails)))
49-
(lambda (h) (equal (equal (house-smokes h) 'Kools)
49+
(lambda (h) (equal (equal (house-hobby h) 'painting)
5050
(equal (house-color h) 'yellow)))
5151
(lambda (h) (equal (equal (house-drink h) 'milk)
5252
(= (house-number h) 3)))
5353
(lambda (h) (equal (equal (house-owner h) 'Norwegian)
5454
(= (house-number h) 1)))
55-
(lambda (h) (equal (equal (house-smokes h) 'Lucky-Strike)
55+
(lambda (h) (equal (equal (house-hobby h) 'football)
5656
(equal (house-drink h) 'orange-juice)))
5757
(lambda (h) (equal (equal (house-owner h) 'Japanese)
58-
(equal (house-smokes h) 'Parliaments)))
58+
(equal (house-hobby h) 'chess)))
5959
(lambda (h) (equal (= (house-number h) 2)
6060
(equal (house-color h) 'blue)))
6161
(lambda (h) (if (equal (house-color h) 'green)
@@ -86,12 +86,12 @@
8686
(= (house-number h1) (1+ (house-number h2)))
8787
t))
8888
(lambda (h1 h2)
89-
(if (and (equal (house-smokes h1) 'Chesterfields)
89+
(if (and (equal (house-hobby h1) 'reading)
9090
(equal (house-pet h2) 'fox))
9191
(next-door? h1 h2)
9292
t))
9393
(lambda (h1 h2)
94-
(if (and (equal (house-smokes h1) 'Kools)
94+
(if (and (equal (house-hobby h1) 'painting)
9595
(equal (house-pet h2) 'horse))
9696
(next-door? h1 h2)
9797
t))))
@@ -117,7 +117,7 @@
117117
(equal (house-owner h1) (house-owner h2))
118118
(equal (house-pet h1) (house-pet h2))
119119
(equal (house-drink h1) (house-drink h2))
120-
(equal (house-smokes h1) (house-smokes h2)))))
120+
(equal (house-hobby h1) (house-hobby h2)))))
121121

122122
(defun extends? (street h)
123123
"Check if a house, H, can be added to a STREET."

0 commit comments

Comments
 (0)