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...
Python question The quicksort algorithm is a recursive algorithm that works by selecting an element, termed...
Python question The quicksort algorithm is a recursive algorithm that works by selecting an element, termed the pivot; dividing the original list into three parts, namely those that are greater than the pivot, those equal to the pivot, and those less than the pivot; and recursively sorting the first and third, appending the results to obtain the final solution. Write a quicksort method that accept a list of numbers and use list comprehension to construct the method. Note that you...
Use python x is a list of strings. For example, x = [’python is cool’, ’pythom...
Use python x is a list of strings. For example, x = [’python is cool’, ’pythom is a large heavy-bodied snake’, ’The python course is worse taking’] In the example, there is totally 1 occurrence of the word ’python’ (case sensitive) in the strings whose length are more than 20 in the list x. In order to count the number of occurrences of a certain word str in the strings which are long enough, use filter and reduce and write...
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...
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers...
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2- Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT