Question

Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers...

Using Haskell to write a program: fillNum

fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer.

For example:

fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8]

fillNum 9 [4,3,2,1] should output [4,3,2,1]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

fillNum :: int->[a]->[a]

fillNum n [a] = take n [a]

Input n the length and list a, the output will be a list with the size of n. Take extracts n elements from the list passed.

Add a comment
Know the answer?
Add Answer to:
Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build...

    Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer. For example: fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8] fillNum 9 [4,3,2,1] should output [4,3,2,1,4,3,2,1,4] fillNum 7 [1,2,3] should output [1,2,3,1,2,3,1]

  • Write a program that takes a list of integer numbers from a user and creates a...

    Write a program that takes a list of integer numbers from a user and creates a new sorted in ascending order list. As output you need to print original list and sorted one. use list and while python

  • Write a program file_max.c that reads a set of integer numbers from a file and prints...

    Write a program file_max.c that reads a set of integer numbers from a file and prints out the maximum number to standard output. The name of the input file should be specified as a command line argument.

  • Write a program that takes these values to find all of the different patterns in "input"...

    Write a program that takes these values to find all of the different patterns in "input" of length "patternLength" and output all of the patterns that occur more than once and the number of times they occur. For example, when searching the string "zf3kabxcde224lkzf3mabxc51+crsdtzf3nab=", with a specified pattern length of 3, the method should return the pattern "abx” with an occurrence value of two, and “zf3” with an occurrence value of three. The answer should be written in C#,

  • In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int...

    In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...

  • Write a function that takes as an input parameter an integer that will represent the length...

    Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number in...

  • Write a program that takes an operation (+, -, /, or *) and two floating-point numbers,...

    Write a program that takes an operation (+, -, /, or *) and two floating-point numbers, and outputs the result of applying that operation to the two numbers. For example, if the input is: + 100 3.14 the output should be 100 + 3.14 = 103.14 Likewise, if the input is * 4 5 the output should be 4 * 5 = 20 You may assume the input is well-formed; that is, the first string is one of the four...

  • Write the following code in C. Write a program that takes a positive integer and prints...

    Write the following code in C. Write a program that takes a positive integer and prints that many stars These are sample outputs. Enter the number of stars: 9 Enter the number of stars: 4 Enter the number of stars: -3 Invalid input!

  • Write a function findEvens that takes an integer, n, as input and returns the list of...

    Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python

  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT