Question

Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a...

Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards

1) Write a function that takes a list of tuples of three integers each and returns a list consisting of just the tuples that are Pythagorean triples. instead of using a list comprehension, use lambda expression and a function that tests one tuple and returns a Bool. As long as the lambda expression is correct, it is OK to make this simpler by having the lambda calls another function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

isTriple :: (Int,Int,Int) -> Bool

isTriple (x, y, z) | (x^2 == y^2 + z^2) = True

| (y^2 == x^2 + z^2) = True

| (z^2 == x^2 + y^2) = True

| otherwise = False

test_all :: [(Int,Int,Int)] -> [Bool]

test_all list_of_tuple = map isTriple list_of_tuple

list_of_bool :: [Bool]

list_of_bool = test_all [(5,12,13),(3,4,5),(1,1,1),(2,5,8)]

main = do

putStrLn "list of tuples is :\n[(5,12,13),(3,4,5),(1,1,1),(2,5,8)]"

putStrLn "\nAfter testing list of Bool is as follow: "

print list_of_bool

Add a comment
Know the answer?
Add Answer to:
Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT