Skip to content

Commit 073efb7

Browse files
authored
Fix order of variables in right triangle example (#151)
Fix order of variables in right triangle generation Signed-off-by: dinomug <47344817+mugcake@users.noreply.github.com>
1 parent 12d1a29 commit 073efb7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

source_md/starting-out.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,25 +878,25 @@ Here's a problem that combines tuples and list comprehensions: which right trian
878878
First, let's try generating all triangles with sides equal to or smaller than 10:
879879

880880
```{.haskell: .ghci}
881-
ghci> triangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10] ]
881+
ghci> triangles = [ (a,b,c) | c <- [1..10], a <- [1..10], b <- [1..10] ]
882882
```
883883

884884
We're just drawing from three lists and our output function is combining them into a triple.
885885
If you evaluate that by typing out `triangles` in GHCi, you'll get a list of all possible triangles with sides under or equal to 10.
886886
Next, we'll add a condition that they all have to be right triangles.
887-
We'll also modify this function by taking into consideration that side b isn't larger than the hypotenuse and that side a isn't larger than side b.
887+
We'll also modify this function by taking into consideration that side *a* isn't larger than the hypotenuse and that side *b* isn't larger than side *a*.
888888

889889
```{.haskell: .ghci}
890-
ghci> rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2]
890+
ghci> rightTriangles = [ (a,b,c) | c <- [1..10], a <- [1..c], b <- [1..a], a^2 + b^2 == c^2]
891891
```
892892

893893
We're almost done.
894894
Now, we just modify the function by saying that we want the ones where the perimeter is 24.
895895

896896
```{.haskell: .ghci}
897-
ghci> rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]
897+
ghci> rightTriangles' = [ (a,b,c) | c <- [1..10], a <- [1..c], b <- [1..a], a^2 + b^2 == c^2, a+b+c == 24]
898898
ghci> rightTriangles'
899-
[(6,8,10)]
899+
[(8,6,10)]
900900
```
901901

902902
And there's our answer!

0 commit comments

Comments
 (0)