• Jason is travelling to an exotic country which has three types of coins.
• Each coin has a different value (5, 10, or 15 units), a different color (red, green, or blue), and a different shape (round, square, and triangular).
• Jason has precisely one of each of the three types of coin in his pocket.
A) If Jason randomly selects one coin, it will either be red, a circle, or the 5 unit coin.
B) If he randomly selects another coin, it will either be blue, a triangle, or the 10 unit coin.
C) The triangular coin is worth more than the square coin.
Determine the color, shape, and value of each coin.
for den=[5 10 15]
for color=['r' 'g' 'b']
for shape=['c' 's' 't']
if color=='r' && shape=='c' || ...
color=='r' && den==5 || ...
shape=='c' && den==5
if color=='b' && shape=='t' || ...
color=='b' && den==10 || ...
shape=='t' && den==10
disp([char(string(den)) ' ' color ' ' shape])
set=[fives(f,:) tens(t,:) fifteens(ff,:)];
disp([fives(f,:) ' ' tens(t,:) ' ' fifteens(ff,:)])
first finds valid coins (for example no coin can have any two of the characteristics among red, circle and 5-unit denomination):
den color shape
5 g s
5 g t
5 b s
10 r s
10 g c
10 g s
15 r s
15 r t
15 g c
15 g s
15 g t
15 b c
15 b s
Then it lists combinations of three coins that don't share attributes:
5 10 15
gt rs bc (color and shape of each denomination)
bs gc rt
In the first row, the triangle (5 units) is worth less than the square (10), violating requirement C.
The second row fits requirement C as the triangle is worth 15 units and the square is worth 5.
a blue square 5-unit coin
a green circular 10-unit coin
a red triangular 15-unit coin.
Posted by Charlie
on 2023-03-03 13:09:56