Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Erlang language- Create a module file named functions3.erl . In this module, write the following functions. Make sure your module name is functions3 , and
Erlang language-
Create a module file named functions3.erl. In this module, write the following functions. Make sure your module name is functions3, and that you export each of these functions.
- Write an Erlang function named sum_between that takes two parameters X and Y. You can assume X and Y are integers, and that X <= Y. The function should return the sum of all the numbers between X and Y, including X and Y. For example, sum_between( 4, 7 ) should return 22, since 4 + 5 + 6 + 7 is 22.
- Weve discovered yet another sequence of numbers! This sequence is defined as follows: the first number is 1, the second number is 2, and the third number is 3. Numbers after that are equal to adding the previous number to the product of the two numbers before that. So, the next number in the sequence would be 5, because 3 + 2 * 1 is 5. The number after that is 11, because 5 + 3 * 2 is 11. The sequence looks like this: 1, 2, 3, 5, 11, 26, 81, 367, Write a function named sequence that takes one parameter N. The function should return the N-th number in this sequence. If N is 0 or less, return 0. If N is not an integer, return error.
- Write an Erlang function named count that takes two parameters, an item and a list. The function should return the number of times that the item occurs in the list. For example, count( 3, [1,3,5,2,3,7,4,1] ) should return 2. Do not use any built-in functions in Erlang.
- Write an Erlang function named remove_all that takes two parameters, an item and a list. The function should return a list with all instances of item removed. For example, remove_all( 3, [1,3,5,2,3,7,4,1] ) should return [1,5,2,7,4,1].
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started