You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source_md/starting-out.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -878,25 +878,25 @@ Here's a problem that combines tuples and list comprehensions: which right trian
878
878
First, let's try generating all triangles with sides equal to or smaller than 10:
879
879
880
880
```{.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] ]
882
882
```
883
883
884
884
We're just drawing from three lists and our output function is combining them into a triple.
885
885
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.
886
886
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*.
888
888
889
889
```{.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]
891
891
```
892
892
893
893
We're almost done.
894
894
Now, we just modify the function by saying that we want the ones where the perimeter is 24.
895
895
896
896
```{.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]
0 commit comments