I need help problem: A two dimensional random walk simulates the behavior of a particle moving in a grid of points. At each step, the random walker moves north, South, east, or West with probability 1/4, independent of previous moves. Compose a program that takes a command line argument n and estimates how long it will take a random walker to hit the boundary of a 2n-by-2n square centered at the starting point.
Q: Given any n by n square matrix, write a program that reflects the matrix across its major diagonal.…
A: In the above problem if we carefully analyze the problem we can see that the result matrix is the…
Q: Write a C++ fraction calculator program that adds, subtracts, multiplies, and divides fractions.…
A: Textual Code :- #include<iostream> #include<math.h> using namespace std;void…
Q: For this assignment you will be replicating the game of Roshambo (aka rock, paper, scissors). Please…
A: The Rock,Paper,Scissors works great for deciding who has to take out the garbage.But you have…
Q: Write an iterative version of the function defined in Self-Test Exercise 2. (Write a recursive void…
A: A recursive function is a function which calls itself until some condition is true. The iterative…
Q: LTtZ|J/ 2/ turtle.right(180) tee2(S/2) turtle.left(90) turtle.back(S) def tee2(S): turtle.forward(S)…
A: The program defines a single function tee( ), which accepts two parameter: S: The height of the…
Q: Tasks: 1. Write an iterative C++ function that inputs a nonnegative integer n and returns the nth…
A: Given: Write code to print nth fibonacci number.
Q: I need to write a recursive Java program to count the number of muck-free regions in a lagoon. The…
A: Attaching the code with screen shot
Q: The SRC of AIT is trying to find out the eligibility of voters in the school for an upcoming…
A: The algorithm ask user to enter A student’s program of study, Student's ID number and Students Year…
Q: Write a recursive function print that, given an integer number p > 0, prints counting forward from 1…
A: #include<iostream>using namespace std;//recursive functionvoid print(int p){ //base…
Q: Take a sorted array of 15 elements of type int and a value x from user, you need to find the ceiling…
A: Given:- Take a sorted array of 15 elements of type int and a value x from user, you need to find the…
Q: Question 1: Consider a country having monetary coins of values (2, 3, and 7). a. Using dynamic…
A: We are authorized to answer one question at a time since you have not mentioned which question you…
Q: Using the functional programming language RACKET solve the following problem: The prime-factors…
A: Racket program: Racket is a general purpose programming language. It is used for web application. It…
Q: python this is connected to the last problem - the second part of the question is added. my attempt…
A: Task : Using the given set of values of n from 2 to 1000 : show that harmonic_sim(n) approaches…
Q: Write an application that solves a system of linear equations. Have the user input the coefficients…
A: #include <iostream> using namespace std; int main(){ //creating array of two lines float…
Q: The following function f uses recursion: def f(n): if n 0 a <- a + i + (i-1) return a c) def…
A: Given: The following function f uses recursion:def f(n):if n <= 1return nelsereturn f(n-1) +…
Q: There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N,…
A: The problem is dp based, where we have 2 options at each step, either pick 1 or 2 Base condition:…
Q: Write a program using any language you'd like that computes the QR factorization of a matrix. You…
A: 1. create a numeric matrix function2.initialize the variables.3. use for loop to traverse through…
Q: for (int i = 1; i < n; i *= 2) { func(i); } void func(int x) { if (x <= 1) return; func(x-1);
A: - The code here is provided of a function and a loop. - We have to find the time complexity of the…
Q: d. Write a function Encode as follows: • // Return M^e mod PQ • int Encode (int M, int e, int PQ);…
A: RSA is a public key encryption algorithm used for secure data transmission. The key generation in…
Q: g(x) = g(x - 1) * g (x - 3) if x is even and x > 3 = g(x - 2) if x is odd and x > 3 = x…
A: The base case is when X is less than or equal to 3 and in all other cases we call the function…
Q: Solve the so-called "Birthday Problem". Write a program that takes an integer N and uses the…
A: Below i have given python code:
Q: 2. (a) Write a function, called myListFn, which takes a single argument n and implements the…
A: Below find the solution !! (a) myListFn <- function(n) { xVec <- rnorm(n) xBar <-…
Q: Write a recursive function F(N) that generalízes the following function: NF(N) 1 4 2 10 3 19 4 37 5…
A: Giving the python recursive function as follows :
Q: Consider the following recursive function: { a if b = 0, %3D f(b, a) 1 f(6, 2. (a f(a, b) if b > a >…
A: Answer is given below .
Q: In C programming Mathematically, given a function f, we recursively define fk(n) as follows: if k…
A: Solution: Given data given a function f, we recursively define fk(n) as follows: if k = 1, f1(n) =…
Q: A number is Zygodrome if it can be partitioned into clusters of repeating digits with a length…
A: function isZygodrome(num) { let chars = num.toString().split(''); let uniques = new Set(chars); let…
Q: For this assignment you will be replicating the game of Roshambo (aka rock, paper, scissors). First,…
A: Solution:-- 1)The given question has required for the solution with the program in the R language…
Q: f (n) \ 1 logn 1 second 2^ 1 day 1 minute 1 hour 1 month nlogn 2" n!
A: Answer: I have done code and also I have attached code as well as output.
Q: Python Programming You are given a list of M positive numbers, Ao, A1, ..., AM-1- You have to answer…
A: Required: We have to write a code in python where we are provided with a list of M positive numbers,…
Q: The following function f uses recursion: def f(n): if n 0 a <- a + i + (i-1) return a c) def f(n):…
A: The Fibonacci sequence is a series of numbers where a number is the addition of the last two…
Q: Problem In this assignment, you are required to implement the fractional knapsack problem. In a…
A: Program:- class ItemValue: def __init__(self, wt, val, ind): self.wt = wt…
Q: our main task is to write a recursive function sierpinski() that plots a Sierpinski triangle of…
A: Given: Sierpinski.java // Height of an equilateral triangle with the specified side length.…
Q: dly until some dice total has repeated n times returns the total number of times the pair of dice…
A: Implement a function rollsToRepeat in Python that simulates a dice game in which a pair of dice are…
Q: There’s a famous puzzle intended to demonstrate the surprising growth of exponentiation sequences,…
A: Below is the code in C++ as language is not mentioned and output:
Q: In C++ Consider the following recursive function (Chapter 17, #9, modified) void recFun(int x)…
A: Given: In C++ Consider the following recursive function (Chapter 17, #9, modified) How can the…
Q: Write a function "sumofEven" that takes an int "n" and returns the sum of all even integers starting…
A: We have to write a function "sumOfEven" to find sum of even numbers from 1 to n we have given sample…
Q: Write a recursive function that takes as a parameter a nonnegative integer and generates the…
A: ## As no language is mentioned, we write the code in Python language. def pattern(n):…
Q: need to write a Java program to check whether a 4 × 4 matrix (4 rows and 4 columns) is a magic…
A: Answer: I have written code in java and also I have attached code .
Q: Write the function root_bisec that solves for f(x)=v with the metod of bisection Use this…
A: C program for Bisection method is implement below
Q: Write a python function that computes an interpolating polynomial through a set of points (xi , yi )…
A: The solution code for the above problem can be found below, for the polynomial coefficients numpy…
Q: Line with most polnts def line_with_most_points(points): 4 point on the two-dimensional grid of…
A: Given the coordinate points as list find the maximum count of points which belong to same line if…
Q: By the "n queens problem" we mean the problem of placing n queens on an nXn “chessboard" in such a…
A: The ask is to find the number of solutions for nXn queens problem, using dynamically allocated…
Q: In python I have N unique coupons that are included in boxes of the cereal being sold. A consumer…
A: All the lines included after the #(hash) are python comments.To print the N unique coupons:for loop…
Q: Presently Nezzar has a beatmap of n particular focuses A1,A2,… ,An. Nezzar might want to reorder…
A: Here have to determine about the Nezzar has a beatmap programming problem statement.
Q: Please help me Josephus Problem is a theoretical problem related to a certain counting-out game. On…
A: N= total number of people and k = after how many people the next number will be eliminated // Java…
Q: Exercise 2: In probability theory, one problem that often arises is determining the number of ways…
A: Algorithm: Start Read n,p values if((n>=0 and n<=20)and (p>=0 and p<=20) and…
I need help problem: A two dimensional random walk simulates the behavior of a particle moving in a grid of points. At each step, the random walker moves north, South, east, or West with probability 1/4, independent of previous moves. Compose a
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- solve the problem in java:Consider the are n=2 subjects and needed =[4,5]answered questions, to pass.The student has answered =[2,4] questions in the two subjects so far, and can answer another q=1 questions across all subjects combined. The best outcome is to answer an additional question in the second subject on order to pass it, as 2 more answers required to pass the first subject. the max number of subject s that can be passed is 1. the function must return an integer that can represent the max number of subjects that can be passed. public static int maxNumsub(List <Integer> answered, List<Integer> needed, int q){//write code here}(Program) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters, such as zerocount, onecount, twocount, and so forth, to 0. Then generate a large number of pseudorandom integers between 0 and 9. Each time 0 occurs, increment zerocount; when 1 occurs, increment onecount; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of time they occurred.python this is connected to the last problem - the second part of the question is added. my attempt on this problem shows that the part b) (approaches N*NH) is not really wokring.. a) (answered) with a function “harmonic(n)” that computes the n-th harmonic number, write a function “harmonic_all(n)” that returns the number of values generated until all values are obtained as a function of the range of possible values n, then write a function “harmonic_sim(n)” that repeats “harmonic_all(n)” a total of n_sim = 100 times. (Attaching the code from the answer for a) d) Show that as n increases (e.g., with a doubling experiment), from n = 2 to n_max = 1,000, the value of “coupon_sim(n)” approaches “n * Hn”.
- Write program in python with a function occupy(n), which shows how birds are going to occupy n nests, assuming that each new bird will choose the nest in the middle of the largest unoccupied run of nests. For example, if there were 10 nests, occupy(10) would print out the following sequence, where underscore indicates an unoccupied nest, and X indicates an occupied nest. The first line of the printout is just 10 underscores showing that all the nests are unoccupied. The second line shows that a bird came to nest in position 5, since that is one the first middle positions of the unoccupied run from 0 to 9. In the third line a bird came to occupy the middle position for the longest open run of nests, from 0 to index 4.Take a sorted array of 15 elements of type int and a value x from user, you need to find the ceilingand floor of x. The ceiling of x is the smallest element in array greater than or equal to x, and thefloor is the greatest element smaller than or equal to x. Assume than the array is sorted inascending order. Write a c++ program using functions to find floor and ceiling of x from the given array.Examples : For example, let the input array be {1, 2, 8, 10, 10, 12, 19}For x = 0: floor doesn't exist in array, ceil = 1For x = 1: floor = 1, ceil = 1For x = 5: floor = 2, ceil = 8For x = 20: floor = 19, ceil doesn't exist in arrayPlease code in C++. Write a program that simulates a coin-tossing game. At the beginning of the game, each of N players has a single fair coin and M points. The game performs a sequence of passes until only a minimum number of players remain. In a pass the players toss their coins into the air and when the coins fall to earth, the players count the number of coins that show heads and the number of coins that show tails. If the number of heads exceed the number of tails, then the players who tossed heads increase their points by an integer P and the players who tossed tails decrease their points by the same integer P. The players perform the opposite actions when the number of tails is greater than the number of heads. If the number of heads equals the number of tails, then no player’s points change. If any player’s points fall below one, then the player leaves the game, never to return. The game employs a second integer K to compute P’s value. K’s and P’s initial values are one.…
- Given two integers x snf y, the following recurrsive definition determined the greatest common divisor of x and y, Write gcd(xy). Write a recursive function, gcd, that takes two integers as parameters and returns the greatest commmon divisorof numbers.Also write a program to test your function. Write a recursive function,reverseDigits, that takes an integer as a parameter snd returns the number with the digits reversed. Also write a program to test your application.* Assignment: Longest increasing subsequence * * Sequences are a natural source of computational problems. One such * family of problems involves finding subsequences with specified * properties in a given sequence. This exercise asks you to write * a program that, given a sequence * * s(0), s(1), ..., s(n-1) * * of integers as input, finds a ___longest increasing subsequence___ * of the sequence s. * * For example, suppose we are given as input the sequence * * 72, 16, 51, 17, 6, 21, 92, 59, 54, 78, 41, 33, 94, * 85, 83, 56, 2, 46, 57, 44, 73, 6, 47, 47, 0. * * In this sequence, a longest increasing subsequence has length 7. * One example of such an increasing subsequence is * * 16 < 17 < 21 < 54 < 56 < 57 < 73. * * More generally, your program must be such that * given a sequence * * s(0), s(1), ..., s(n-1) * * of integers as input, the program returns a subsequence * * s(i_1), s(i_2), ..., s(i_k) * * that meets all…For this assignment you will be replicating the game of Roshambo (aka rock, paper, scissors). Please answer both parts a and b of the following question below. Show the R code in your answer and annotate all parts of the code. a.) First, you need to come up with a strategy to win the game. Write a function in R that takes in a vector of past plays for your opponent (each play should be represented as "R", "P", or "S") and outputs the next move ("R", "P", or "S"). Your strategy should at least depend on the last two moves used, but you should return a random move if there is not enough past history to use the strategy. b.) Now, play your strategy against a random player who uses rock, paper, or scissors with 1/3 probability each. Who wins the most rounds after 100 rounds of play? Write a function in R.
- (IN PYTHON) Problem 2 Write a function count_8s(string) that performs the following actions: Receives a single parameter called string that we expect to be a string. If we receive something that is NOT a string, raise a TypeError with the message “Non-string input received.” Uses recursion to count the number of eights in the string. Use a string of length 0 as your base case. Otherwise, determine if the first character in string is “8” or not, and call count_8s() again with the rest of the string as an argument. Returns the number of eights found in the string. NOTE: You are not to use a while or for loop in your code.a) Write a non-recursive function in C++/ to multiply all even numbers from 2 to n, where n is an input to the function, and n>=2. (reminder: An even number is divisible by 2 and generates a remainder of 0. for example 2,4,6,... are even numbers). b) Analyze your algorithm in part (a) in the worst-case. Show all your work. Then express the time as Big-O().code in python (A) please Solve the so-called "Birthday Problem". Write a program that takes an integer ?N and uses the function np.random.randint (low = 0, high = N) from numpy to generate a random sequence of integers between 00 and ?−1N−1. Run experiments to validate the hypothesis that the number of integers generated until the first repeated value is approximately ?∗?2⎯⎯⎯⎯⎯⎯⎯√π∗N2. a) Write a function birthday(N) that returns the number of values generated until a value is repeated as a function of the range of possible values ?N (from 00 to ?−1N−1); b) Write a function birthday_sim(N) that repeats birthday(N) a total of n_sim = 20000 times and returns the average of all the numbers generated; c) Show on one plot that as ?N increases (with a doubling experiment), from ?=2N=2 to ?=1000N=1000, the value of birthday_sim(N) approaches ?∗?2⎯⎯⎯⎯⎯⎯⎯√π∗N2.