In Haskell programming language
(1) Write a "averageThree" function to return the average
of three integers.
averageThree :: Integer -> Integer -> Integer ->
Float
(2) Write a "howManyAboveAverage" function which returns
how many of three integer inputs are above its average value.
(utilize the averageThree function.)
howManyAboveAverage :: Integer -> Integer -> Integer
-> Integer
(3) Write a "howManyWithinThreshold" function that
returns how many of the first three arguments are within the
threshold (the fourth argument) of the average of the first three
arguments. (utilize the averageThree function and the logic in the
howManyAboveAverage function.)
howManyWithinThreshold :: Integer -> Integer -> Integer
-> Float -> Integer
I personally have completed (1) and (2)!
[sample of (1)]
averageThree :: Integer -> Integer -> Integer ->
Float
averageThree a b c = (fromIntegral (a + b + c)) / 3
All i need help with is 3, where i am stuck and can not resolve!
Source Code:
module main where
--averageThree to return the average of three integers
averageThree :: Integer -> Integer -> Integer ->
Float
averageThree x y z = fromInteger(x*y*z)/3
--howManyAboveAverage that returns how many of three integer
inputs are above its average value
howManyAboveAverage :: Integer -> Integer -> Integer ->
Integer
howManyAboveAverage x y z
| x > round(averageThree x y z) && y >
round(averageThree x y z) = 2
| y > round(averageThree x y z) && z >
round(averageThree x y z) = 2
| x > round(averageThree x y z) && z >
round(averageThree x y z) = 2
| x==y && y==z = 0
| otherwise = 1
--howManyWithinThreshold that returns how many of the first
three arguments are within the threshold
--(the fourth argument) of the average of the first three
arguments.
howManyWithinThreshold :: Integer -> Integer -> Integer ->
Float -> Integer
howManyWithinThreshold w x y z
| ((averageThree w x y)-z) < fromInteger(x) &&
((averageThree w x y)+z) > fromInteger(x) &&
((averageThree w x y)-z) < fromInteger(y) &&
((averageThree w x y)+z) > fromInteger(y) &&
((averageThree w x y)-z) < fromInteger(w) &&
((averageThree w x y)+z) > fromInteger(w) = 3
| ((averageThree w x y)-z) < fromInteger(x) &&
((averageThree w x y)+z) > fromInteger(x) &&
((averageThree w x y)-z) < fromInteger(y) &&
((averageThree w x y)+z) > fromInteger(y) &&
((averageThree w x y)-z) > fromInteger(w) || ((averageThree w x
y)+z) < fromInteger(w) = 2
| ((averageThree w x y)-z) < fromInteger(x) &&
((averageThree w x y)+z) > fromInteger(x) &&
((averageThree w x y)-z) > fromInteger(y) || ((averageThree w x
y)+z) < fromInteger(y) && ((averageThree w x y)-z) <
fromInteger(w) && ((averageThree w x y)+z) >
fromInteger(w) = 2
|((averageThree w x y)-z) > fromInteger(x) || ((averageThree w x
y)+z) < fromInteger(x) && ((averageThree w x y)-z) <
fromInteger(y) && ((averageThree w x y)+z) >
fromInteger(y) && ((averageThree w x y)-z) <
fromInteger(w) && ((averageThree w x y)+z) >
fromInteger(w) = 2
|((averageThree w x y)-z) < fromInteger(x) &&
((averageThree w x y)+z) > fromInteger(x) &&
((averageThree w x y)-z) > fromInteger(y) || ((averageThree w x
y)+z) < fromInteger(y) && ((averageThree w x y)-z) >
fromInteger(w) || ((averageThree w x y)+z) < fromInteger(w) =
1
|((averageThree w x y)-z) > fromInteger(x) || ((averageThree w x
y)+z) < fromInteger(x) && ((averageThree w x y)-z) <
fromInteger(y) && ((averageThree w x y)+z) >
fromInteger(y) && ((averageThree w x y)-z) >
fromInteger(w) || ((averageThree w x y)+z) < fromInteger(w) =
1
|((averageThree w x y)-z) > fromInteger(x) || ((averageThree w x
y)+z) < fromInteger(x) && ((averageThree w x y)-z) >
fromInteger(y) || ((averageThree w x y)+z) < fromInteger(y)
&& ((averageThree w x y)-z) < fromInteger(w) &&
((averageThree w x y)+z) > fromInteger(w) = 1
| otherwise = 0
Hope this helps!
In Haskell programming language (1) Write a "averageThree" function to return the average of three integers....
Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool
I need help solving this problem using the ML programming language Write a function sqsum of type int -> int that takes a non-negative integer n and returns the sum of the squares of all the integers 0 through n. Your function need not behave well on inputs less than zero
I need help solving this problem using the ML programming language Write a function min3 of type int * int * int -> int that returns the smallest of three integers.
IN HTML Programming 1. Write a script that inputs integers (one at a time) and passes them one at a time to function isEven, which uses the modulus operator to determine whether an integer is even. The function should take an integer argument and return true if the integer is even and false otherwise. Use sentinel-controlled looping and a prompt dialog.
Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...
C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....
*Coral Language* Write a program that first gets a list of six integers from input. The first five values are the integer list. The last value is the upper threshold. Then output all integers less than or equal to the threshold value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Such functionality is common on sites like...
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...
4. Write a C definition (prototype) for a function called power which takes a float and an integer as inputs, and returns a float as a result. 5. Write the body of the function from (4). This function should raise the first argument to the power of the second, by multiplying it by itself that many times (don’t use the inbuilt pow function, write your own). Do not worry about “special” cases like negative powers. Please do Q.5
Give a function to return the average of three integers averageThree : : Int -> Int -> Int -> Float discreet structures