Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write a code to solve the 3 problems and explain each line in plain English (javascript only) Evaluation: In class, one at the time, the
write a code to solve the 3 problems and explain each line in plain English
(javascript only)
Evaluation: In class, one at the time, the students will be asked to a) run the program under different inputs and b) to explain any particular lines of code within the program. Problem #1. Input is n and three points in the plane = (X,Y).Q = (X,Y), R = (X3, Y3). Program should print out all the points within the square (0,n)*(0,n) that have INTEGER coordinates and that lie within the triangle determined by points P, Q and R. Problem #2. Input is n, and the program should print out two CONSEQUTIVE primes PI and P2 , for which the difference P2-P1 is the maximum among all the primes less than n. Example: If n=20,then P1=7 and p2=11 would qualify. (since primes are 2,3,5,7,11,13,17, and max difference between two consecutive primes is 11-7-4). Comment: if there are more than one such pair, computer should print the smallest pair. Problem #3. Imagine a "walk" on X-Y coordinate that is along the "integer spiral". Example, you start at point(0,0), next step is (1,0), then (1,1), then (0,1) then (-1.1) then (-1,0) then (-1,-1) then (0,-1) then (1,-1) then (2,-1),...and continue like this indefinitely. Input is n-number of steps, and output is the (x,y) coordinate after n-steps. Example: n=2 output is (1.1) for n=5 output is (-1,0). Evaluation: In class, one at the time, the students will be asked to a) run the program under different inputs and b) to explain any particular lines of code within the program. Problem #1. Input is n and three points in the plane = (X,Y).Q = (X,Y), R = (X3, Y3). Program should print out all the points within the square (0,n)*(0,n) that have INTEGER coordinates and that lie within the triangle determined by points P, Q and R. Problem #2. Input is n, and the program should print out two CONSEQUTIVE primes PI and P2 , for which the difference P2-P1 is the maximum among all the primes less than n. Example: If n=20,then P1=7 and p2=11 would qualify. (since primes are 2,3,5,7,11,13,17, and max difference between two consecutive primes is 11-7-4). Comment: if there are more than one such pair, computer should print the smallest pair. Problem #3. Imagine a "walk" on X-Y coordinate that is along the "integer spiral". Example, you start at point(0,0), next step is (1,0), then (1,1), then (0,1) then (-1.1) then (-1,0) then (-1,-1) then (0,-1) then (1,-1) then (2,-1),...and continue like this indefinitely. Input is n-number of steps, and output is the (x,y) coordinate after n-steps. Example: n=2 output is (1.1) for n=5 output is (-1,0)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