(6) Make a list of all the positive integers which are equal to the order of...
From previous homework you are already familiar with the math function f defined on positive integers as f(x)=(3x+1)/2 if x is odd and f(x)=x/2 if x is even. Given any integer var, iteratively applying this function f allows you to produce a list of integers starting from var and ending with 1. For example, when var is 6, this list of integers is 6,3,5,8,4,2,1, which has a length of 7 because this list contains 7 integers (call this list the Collatz list for 6). Write a C or C++...
(+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100) to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0 (how many) Display the number of integers < 0 (how many) Display the...
Given a single linked chain of nodes with positive integers, write an algorithm in pseudocode to rearrange the nodes in one pass in such a way that all integers that are odd appear at the end. The relative order of the elements does not need to remain the same. List all the steps in the proper order that are necessary to rearrange the nodes, show how the next pointers are being changed. Each data element should “stay” in its original...
Java Create a class NumberList that stores a list of integers and a list of doubles. Create a driver class that creates two objects of type NumberList and and ask the user to fill one of these lists. The other list should have integer values 1,2,3,4 and double values 1.1, 2.2, 3.3, 4.4. Declare a winner between the two objects by comparing their integer lists element by element and counting which list has more winning positions (the lists will need...
Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return: 1. List (of tuples) containing all pairs of numbers in L that are coprime. 2. Empty list, If no pair of numbers in L is coprime. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is...
(3.5) Summing the Euler S-function (n): The Euler 6-function 6(n) counts the number of positive integers less than or equal to n, which are relatively prime with n. Evaluate 4(d), and prove that your answer is correct. (3.4) Relatively Prime Numbers and the Chinese Re- mainder Theorem: Give an example of three positive integers m, n, and r, and three integers a, b, and c such that the GCD of m, n, and r is 1, but there is no...
Two positive integers are amicable if each prime divisor of one is a divisor of the other. Example: 6 and 12 are amicable, since each prime divisor of 6 (2 and 3) also divides 12, and each prime divisor of 12 (again 2 and 3) divides 6. Another: 12 and 15 are not amicable, since a prime divisor of 15 (namely 5) does not divide 12. Find the sum of all amicable pairs whose two members are both less than...
4) Let D be the set of all finite subsets of positive integers. Define a function (:2 - D as follows: For each positive integer n, f(n) =the set of positive divisors of n. Find the following f (1), f(17) and f(18). Is f one-to-one? Prove or give a counterexample.
with python
Write a function called linear_search which consumes a sorted list of integers and a number and linearly searches for the number in the list. Your function should return how many comparisons were made in order to find the element in the list. If the element is not in the list, your linear search should return -1 For example:
8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...