Need help writing simple Haskell program please

  • Thread starter Thread starter chuy52506
  • Start date Start date
  • Tags Tags
    Program Writing
AI Thread Summary
The discussion centers around implementing a function, `addPairs`, that takes a minimum distance and a list of integer pairs, returning a list of their sums if the pairs meet the distance requirement. The example provided illustrates that for the input `addPairs 10 [(2,3),(4,15),(87,92),(23,45)]`, the expected output is `[19, 68]`, as only the pairs (4,15) and (87,92) have a difference greater than or equal to 10. The user has started coding the function with a helper function, `diffTuple`, to calculate the absolute difference between pair elements. However, the implementation of `addDistantPairs` is incomplete and needs refinement to correctly filter and sum the pairs based on the specified distance condition. The discussion seeks assistance in completing this function.
chuy52506
Messages
77
Reaction score
0
So for my program I want to input this line of code:

addPairs 10 [(2,3),(4,15),(87,92),(23,45)]

Where the 10 after addPairs is the minimum distance the pair (x,y) must have in order to be outputted as [x+y]
For example :
addPairs 10 [(2,3),(4,15),(87,92),(23,45)]

would output:
[ 19, 68 ]

SO far this is what I have:

diffTuple :: (Int,Int) -> Int
diffTuple (x,y) = abs (x-y)

addDistantPairs :: addDistantPairs :: Int -> [(Int,Int)] -> [ Int ]
addDistantPairs n [(x,y)]
| diffTuple(x,y)>= n = addPairs[(x,y)]
| otherwise = [0]
 
Technology news on Phys.org
anyone??
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top