Skip to content

Instantly share code, notes, and snippets.

@gpaulu
Forked from anonymous/ sumPair.hs
Last active September 24, 2021 13:46
Show Gist options
  • Save gpaulu/4449746 to your computer and use it in GitHub Desktop.
Save gpaulu/4449746 to your computer and use it in GitHub Desktop.
Reddit Challenge 115 Description: Let the term "sum-pair" be a pair of integers A and B such that the sum of A and B equals a given number C. As an example, let C be 10. Thus, the pairs (5, 5), (1, 9), (2, 8), etc. are all sum-pairs of 10. Your goal is to write a program that, given an array through standard input (console), you echo out all sum…
sumPair options num :: [Int] -> Int -> [(Int,Int)]
sumPair options num = [(x,y) | x <- options, y <- options, x + y == num, x < y] ++ [(x,x) | x <- options, x*2 == num]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment