Question

Haskell Complete the following function definition: stutter n x should return a list of length n...

Haskell

Complete the following function definition: stutter n x should return a list of length n where each element is x. E.g., stutter 3 5 = [5,5,5]. Use a list comprehension to produce the result. Note stutter 0 x = []. Don't worry about n < 0; the canonical solution makes stutter return [].

stutter n x = ???

Homework Answers

Answer #1

The code will be

stutter :: Int->a->[a]

stutter 0 y = []

stutter x y = [y|_<-[1..x]]

Know the answer?
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
Similar Questions
Complete a function definition in C for strmatch. For this problem, you can't use any <string.h>...
Complete a function definition in C for strmatch. For this problem, you can't use any <string.h> library functions. In c, two strings match exactly if they have the same characters in the same order and same length. Consider this: int strmatch(const char *x, const char *b); //Needs each of x and y points to the beginning of a string. //Promises to return value 1 if the two strings match exactly. If they don't match, the return value is 0. For...
Recall the function definition of creating a 2D list representing a screen of pixels: def create_screen(rows,...
Recall the function definition of creating a 2D list representing a screen of pixels: def create_screen(rows, columns): ''' Creates a screen of rows x columns pixels ''' grid = [] for x in range(rows): grid.append([0] * columns) return grid Complete the following function definition according to the docstring comment and assert examples below: def count_pixels(screen): ''' The parameter screen has arbitrary values and dimension (represented as a 2D list). Return the number of pixels with a value equal to 0....
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most factors (divisors without remainder). For example: >>> most_factors([5,10,16,20,25]) 20 # because 20 has the most factors of any of these numbers # 6 factors, i.e., [1, 2, 4, 5, 10, 20] >>> most_factors([1, 2, 3, 4, 5]) 4 # because 4 has the most factors of any of these numbers # 3 factors, i.e., [1, 2, 4] Hints: For each element in numbers, call...
Complete following function which receives an array of integers and the length of the array, and...
Complete following function which receives an array of integers and the length of the array, and then returns the sum of all the positive numbers in the array. For example, if an array that is passed to this function contains following numbers: -1, 2, 0, 3, 4, -3, 0, 2, 0, and then the return value of the function should be 11. Will this function be working correctly? Yes or No? int sumPositive(int a[],int length) { int s=0;     for(int...
1. Code is already written please show all outputs and comment on function of code. 2....
1. Code is already written please show all outputs and comment on function of code. 2. These are Python 3 programs. Please show outpouts and comment on fuctions. Note: this is a bit of a “backwards” exercise – we show you code, you figure out what it does. As a result, not much to submit – don’t worry about it – you’ll have a chance to use these in other exercises. >>> feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros(...
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros( 1, n + 1 ) ; Y(1) = 1 ; for k = 1 : n m = Y(k) ; Y(k + 1) = Y(k) + m*( X(k + 1) - X(k) ) ; end clf plot( X, Y ) Create a new script, which defines the function EulerMethod2. The purpose of EulerMethod2 is to use Euler's Method to approximate the solution to the...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
Complete this function (the instructions are below the code): private static int numCommonElements(int A[], int B[],...
Complete this function (the instructions are below the code): private static int numCommonElements(int A[], int B[], int lenA, int lenB) { // Complete this function. } We want to solve the following problem: given two sorted arrays A[n] and B[m] of length n and m respectively, we want to nd the number of elements that are common to both the arrays (without repeated counting of the same element). For example, the arrays A[ ] = {7; 13; 19; 20; 22;...
1. Answer the questions about the following function. f(x) = x + 11 / x -...
1. Answer the questions about the following function. f(x) = x + 11 / x - 9 (a) Is the point (4, - 17 /3) on the graph of f? A. Yes, because substituting x = - 17 / 3 into the given equation results in 4. B. Yes, because substituting x = 4 into the given equation results in - 17 / 3. C. No, because substituting x = 4 into the given equation does not result in -...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT