2. Write a function that multiplies a polynomial by a constant (or scalar). scale :: (Num a, Eq a) => a -> Poly a -> Poly a For example: > scale 2 (P [-1,0,1]) P [-2,e,2] > scale e (P [0,0,2]) P []
Q: Write a function solver that takes a non-negative integer upper_bound as an argument, and prints…
A: Step-1: Define a helper function is_perfect_square(n) Step-1.1: Compute the square root of n…
Q: domain and range
A: According to the question we need to find the domain and range of the function: f(x) = 1/(x3 - 3x2 +…
Q: Given an algorithm with the recurrence relation of T(n) = T(n-1) +n. what is the Big O runtime? This…
A: Big O notation: F(n)=O(G(n)) if and only if F(n) ≤C.G(n) for some constant C such that C>0 and…
Q: 4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the…
A: import java.io.*; import java.util.Scanner; class Polynomial { public static Node…
Q: I have two functions in a function, one has a time complexity of O(n) and the other one has a time…
A: Time complexity is measured using the Big-O notation.
Q: Write one function dn(n) which takes a non negative integer n returns a tuple list L. Must use…
A: Given :- Write one function dn(n) which takes a non negative integer n returns a tuple list L. Must…
Q: Write a function that takes a two-digit number and determines if it's the largest of two possible…
A: 1. Created the new method and passing Number argument2. Created the new variable Newnum3. Perform…
Q: Must be new solution! Using Lisp, implement a program that solves the Missionaries and Cannibals…
A: The objective of the question is to implement a solution to the Missionaries and Cannibals problem…
Q: Write a function linear_independence that takes a collection of vectors with integer entries (each…
A: Linear independence is defined as the central concept in linear algebra as a set with one vector is…
Q: 10. Simplify the following function using Karnaugh maps: F(A,B,C,D) =E(3,7,11,13,14,15) Final…
A:
Q: Prompt the user to key in the number of views of 5 YouTubers' debut video. • Identify which YouTuber…
A: Program : declare an Array to store the values of number of views of each youtuber.…
Q: def arange(start, end, step=1): arange behaves just like np.arange(start, end, step). You only need…
A: Python code is given below to implement a function arrange which behave just like np.arange (start…
Q: Write one function du(a,b) which returns a list of a b times (b>=0). Must use identical function…
A: Here function defintion is given , du(a,b) So here is the code given below with proper comments:…
Q: A university assigns student IDs of the form 1, 2, 3, . such that if n students are currently…
A: Solution :: Let's see first what is thread and its uses ? Answer :: In computer science, a thread…
Q: Write a function SoftMax(Q) as seen in the photo
A: #import numpy moduleimport numpy as np#function which computes softmax function values for the given…
Q: Subtask I: Now that you can represent cards, you'll attempt to represent poker hands. Poker is one…
A: I have given the full classes with functions so it will be easier to understand and have also added…
Q: Consider the continuous function x2 + 2x + 3 if æ < 0 if 0<I< 2 2² + 4x – 7 if 2 < z. f(r) = {r+3…
A: Code: tempFn <- function(xVec){ f = integer(length(xVec)) for (i in seq(1, length(xVec)))…
Q: Create a function that takes numbers b, m, and nas arguments and returns the definite integral of…
A: Since no programming language is mentioned, I am using Matlab. Algorithm: Start Define a method…
Q: Write an R function called fibo(k) to obtain the Fibonacci numbers less than its argument k.
A: Fibonacci numbers: The Fibonacci numbers are the numbers in the following integer sequence.0, 1, 1,…
Q: C+ Programming Problem: You are given n sets S1, S2,..., Sn. For each i, you want to choose x; E Si,…
A: Coded using C++.
Q: My questions is in this example I read from my R textbook: test_function = function(x) { x[x<0] =…
A: The given R function test_function = function(x) { x[x<0] = -x[x<0] return(x)} is designed…
Q: iterse def squares_intersect (s1, 82): An axis-aligned square on the two-dimensional plane can be…
A: # TEXT CODE:
Q: The programming language is Python
A: TASK: To create a python function to print Fn, Fn+1 term of Fibonacci series. all code and…
Q: Define function f() and g () in this way def >>.(y): x=2 print ( ' in f (): x = {}, y= {} '…
A: The python program was developed as per the requirement specified in the prompt. And, the program is…
Q: In the game of Connect Four, two players take turns playing on an n x n board, which we represent as…
A: Algorithm: Start Implement a method named check that takes a list of strings as argument Inside the…
Q: Create a function that takes numbers b, m, and nas arguments and returns the definite integral of…
A: In this problem, we need to design the code in the java Script programming language. Input -…
Q: In the game of Connect Four, two players take turns playing on an n x n board, which we represent as…
A: The game is called Connect Four. It is played on an n x n board, which is represented as a 2D list…
Q: find the output for the following function 1) void fun(node* head, int x) { node* current = head;…
A: For the first iteration of while loop : Initially head is storing the data 5 and pointing to it. It…
Q: This is to be done in ML coding language. Please provide the actual code, and try to keep the code…
A: The ML code is given below with output screenshot
Q: Let f(x) = [x²/3]. Find f(S) if а) S3D {-2, — 1, 0, 1, 2, 3}.
A: The given set is S = [-2, -2, 0, 1, 2, 3] And the function if f(x) = x2/3 so calculating the values…
Q: Computer Science Exercise: depth [★★] Write a function depth : 'a tree -> int that returns the…
A: Answer: I have done code and also I have attached code and code screenshot as well as output
Q: I need this answer in Haskell Programming language only. 2. Write a function that multiplies a…
A: ALGORITHM:- 1. Define a function scale that takes a constant and a polynomial and multiplies them.…
Q: Write a definition for the following C++ function:bool up_then_down(const int* arr, int n);//…
A: The objective of the question is to write a C++ function that checks if the sequence of element…
Q: Write a function nth_largest that takes any list of numbers num_lst and a positive integer n, and…
A: The problem is based on finding nth largest number in a list. NOTE: The code given in the solution…
Q: . If A has n elements and B has m elements(n, m ∈ N),find the number of functions from A to B
A: Given that, Number of elements in A= n Number of elements in B= m The formula for finding the number…
Q: Using Selection Sort, Write a function sort_matrix_by_columnNumber which takes as parameter a matrix…
A: Required: Sort Matrix By Column Number Using Selection Sort Write a function…
Q: I Complete the Python function MySpline that reads in a set of x and y values (each as arrays or…
A: implementation of the MySpline function in Python: import numpy as np def MySpline(x, y): n =…
Q: The question is in bold and the rest is there for support , to explain concepts Write a function…
A: Step 1 : STARTStep 2 : Implement the function triple_riffle(mylist)Step 3 : Implement the function…
Q: A quadratic function is a function of the form f(x) = ax**2 +bx + c Define a function…
A: Refer to the code below for your above-asked problem
Q: Extend the JML definition of Peano from the lecture with a function computing the minimum of two…
A: Answer: Algorithms Step1: We have ask for user input first number Step2: We have ask for user input…
Below is the code in python as language not specified and sample output:
Step by step
Solved in 3 steps with 1 images
- Remember that an integer n is prime if (i) n> 2 and (ii) it is only divisible by 1 and n itself. Subtask I: You will start by implementing a function is_prime(n: int) -> bool that returns True if the number n is prime and False otherwise. For example: • is_prime(1) should return False. is_prime(2) should return True. is_prime(-2) should return False. is_prime(5) should return True. • is_prime(41) should return True. • is_prime(323) should return False. Subtask II: The thing is, many people believe prime numbers bring sadness and must be avoided. To this end, you'll write a function sans_primes(numbers: list[int]) -> list[int] that takes in a list of integers and returns the numbers in the input list in the original order, except that every prime number is banned, so it will be excluded and numbers that come immediately after a prime number will also be excluded. For example: • sans_primes([1, 4, 9, 10]) should return [1, 4, 9, 10]. • sans_primes([1, 11, 9, 10, 17]) should return [1,…I need this answer in Haskell Programming language only. 4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the requirements. addPoly :: (Num a, Eq a) => Poly a -> Poly a -> Poly a For example: > addPoly (P [1]) (P [-1,1])P [0,1]> addPoly (P [17]) (P [0,0,0,1])P [17,0,0,1]>addPoly (P [1,-1]) (P [0,1])P [1] You may find it helpful to write addPoly using two helper functions: one to combine the lists of coefficients, and one to trim trailing zeroes. Your implementation of addPoly should have this property: addPoly p q $$ x == (p $$ x) + (q $$ x)Correct and detailed answer will be Upvoted In C Question: How can the function, matrix_initialize_unopt, be optimized and rewritten with loop collapsing? n has a size of 3000 struct fn_args { int n; int *mem1; int *mem2; }; int check(int x, int y) { return x < y; } void set(int *mat, int i, int num) { mat[i] = num; } void matrix_initialize_unopt(struct fn_args *args) { int i, j, n; int *mat1, *mat2; n = args->n; mat1 = args->mem1; mat2 = args->mem2; for (i = 0; check(i, n); i++){ for (j = 0; check(j, n); j++){ set(mat1, i * n + j, i); set(mat2, i * n + j, i+1); } } }
- Write an R function called fibo(k) to obtain the Fibonacci numbers less than its argument k. Example: > fibo(20) [1] 0 1 1 2 3 5 8 13 > fibo(100) [1] 0 1 1 2 3 5 8 13 21 34 55 89 > fibo(1000) [1] 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987write a C++ function to compute the following (Set Theory) a. std::vector<int> intersection(std::vector<int>& a, std::vector<int>& b) b. std::vector<int> union(std::vector<int>& a, std::vector<int>& b) c. std::vector<int> abs_complement(std::vector<int>& u, std::vector<int>& a, std::vector<int>& b) d. std::vector<int> relative_complement(std::vector<int>& u, std::vector<int>& a, std::vector<int>& b) //a\b e. std::vector<int> delta_diff(std::vector<int>& u, std::vector<int>& a, std::vector<int>& b) //a = { x, y, z ... } void print(std::vector<int>& v, std::string& n) { std::vector<int>::iterator itr = std::begin(v); for (; itr != std::end(v); itr++) { std::cout<<(*itr)<<std::endl; } } int main(int avgc, char** avgs) { std::vector<int> u = {1, 2, 3,…Let's assume the deck has n cards and it's cut at m cards. The cut takes the first card off the deck and places it face down, then takes the second card and places it face down on top of the first, and this continues up until and including the mth card. The remainder of the deck, n – m cards, is simply placed on top of the deck of face-down cards. function deck_1(n, m) { // Your code goes here // Return the new location of the // last card which was at offset n-1 return 0; } INPUT: n and m where [n/2] < mmachine learning coding in PythonTask 1. Area between two curves Consider the graphs of the functions f(x) = m-x and g(x) = 2x². - n where m and n are the maximum and mean values of the digits in your student-ID number. student-ID number=201904598 a) Create a vector v whose elements are the digits of your student-ID number. b) Create a variable m and assign the maximum digit in v to it. c) Create a variable n and assign the mean value of the digits in v to it. d) Define the function f(x) and g(x) above as anonymous functions. e) Plot the graphs of f(x) and g(x) on the same figure using the MATLAB function ezplot. f) Find the exact values of the x-coordinates of the intersection points between the two graphs using the MATLAB function solve. g) Find the area bounded by the two graphs.Which of the following is the definition of a higher-order function? func xs = sum (map (^2) xs) func x = x * 2 func (x,y) = (y,x) func (x:y:zs) = y func f [x,y] = [f x, f y]For input vector x, write a function to check whether there exists at most 5 elements in x whose values are less than 7.Change two lines of code of: def solution(A, K): n = len(A) for i in range(n - 1): if (A[i] + 1 < A[i + 1]): return False if (A[0] != 1 and A[n - 1] != K): return False else: return True SO that it solves the question : you are given a implementation of a function def solution (A,K) This function, given a non-empty array A of N integers (sorted in non-decreasing order) and integer K, checks whether A contains numbers 1,2..K (every numbers from 1 to K at least once and no other numbers (for example given array A, K=3 ; A(0)=1, A(1)=1, A(2)=2, A(3)=3, A(4)=3 then the function should return True while for the following array A, K=2; A(0)=1, A(1)=1, A(2)=3 then the function should return False.) Assume that: -N and K are integers within the range (1....300,000) -each element of array A is an integer within the range (0...1,000,000,000) -array A is sorted in non-decreasing orderA university assigns student IDs of the form 1, 2, 3, ... such that if n students are currently enrolled, then the next student to enroll will receive and ID of n + 1. Consider the following algorithm that accomplishes this. // Global variable storing number of students currently enrolled current_student_count = 0 // Function that reads the above global variable, calculates new ID, and increments the global count assign_new_id(): count = current_student_count new_id = count + 1 current_student_count = count + 1 return new_id (a) If two different threads run the above code in parallel to enroll two different students, it is possible for the two students to receive the same ID, and for the current_student_count to have a wrong value. Explain how this is possible. (b) Modify the code above so that the problem in (a) does not happen.SEE MORE QUESTIONS