Question

In: Computer Science

There are two lights that blink at regular intervals. When each one blinks, it turns on...

There are two lights that blink at regular intervals. When each one blinks, it turns on and then immediately back off; they don’t toggle. They are both off at time t=0t=0. The first one blinks at t=p,2p,3p,…t=p,2p,3p,… seconds; the second one blinks at t=q,2q,3q,…t=q,2q,3q,… seconds. Once they start, they both keep blinking forever. It is very exciting to see them blink at the same time (on the same second). But your patience is going to run out eventually, in ss seconds. Will they blink at same time between t=1t=1 and t=st=s (inclusive)? Write a program that can answer this question, quick, before they start blinking again!

Solutions

Expert Solution

Output:

Writable Program:

#include<iostream>
#include<vector>

using namespace std;

bool checkLight(int p,int q,float s){

vector<int> A;
vector<int> B;
int store;

int n;
int i=1;
do{
     n = i*p;
     A.push_back(n);
      i++;
}while(n<=s);

A.pop_back();


int j=1;
do{
     n = j*q;
     B.push_back(n);
     j++;
}while(n<=s);

B.pop_back();

for (int i=0; i<A.size(); i++)
    {
        // Check any element is equal
        int j;
        for (j=0; j<B.size(); j++) {
           if (A[i] == B[j]) {
               cout<<"Yes";
               return 1;
           }
        }

    }


return 0;
}

int main(){
    int p,q,s;
    cin>>p>>q>>s;
    if(checkLight(p,q,s)){
        return 0;
    }
    else{
        cout<<"no"<<endl;
    }
}

Hope I answered the question.

If you have any doubts, or queries, feel free to ask

I'll respond to you as soon as I can.

Have a nice day


Related Solutions

Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
samples of n=4 items each are taken from a manufacturing process at regular intervals. a quality...
samples of n=4 items each are taken from a manufacturing process at regular intervals. a quality characteristic is measured, and x-bar and r values are calculated for each sample. after 25 samples, we have: x-bar = 107.5 r = 12.5 assume that the quality characteristic is normally distributed. a)compute control limits for the x-bar and r control charts b)estimate the process mean and standard deviation c)assuming that the process is in control, what are the natural tolerance limits of the...
A transformer is plugged into a regular U.S. Wall outlet. There are 200 turns in the...
A transformer is plugged into a regular U.S. Wall outlet. There are 200 turns in the primary coil, and 4000 turns in the secondary coil. A) What is the rms voltage and peak voltage on the secondary coil? (two answers) B) An electrical worker accidently grabs one of the loops of the secondary coil with a single bare hand. Her other hand is in midair, and both of his shoes are firmly on the ground. The resistance in her body...
Two monochromatic light sources produced green and orange lights. The two lights in water strikes a...
Two monochromatic light sources produced green and orange lights. The two lights in water strikes a diamond surface at the same point of incidence and at an angle of 52.0° with the surface (not the normal). The indices of refraction of diamond for green and orange lights are 2.45 and 2.42 respectively. (a) Calculate the angle of dispersion of the two colors in diamond if the lights are passing from a liquid to diamond (index of refraction of water is...
5. A driver encounters two traffic lights on the way to work each morning. Each light...
5. A driver encounters two traffic lights on the way to work each morning. Each light is either red, yellow, or green. The probabilities of the various combinations of colors is given in the following table: Second Light First Light R Y G R 0.31 0.02 0.18 Y 0.02 0.03 0.03 G 0.14 0.04 0.23 a) What is the probability that the first light is red? b) What is the probability that the second light is green? c) Find the...
Write a function that can be used to blink an LED when called.
Write a function that can be used to blink an LED when called.
The insulin pump is a device that delivers insulin to a diabetic patient at regular intervals....
The insulin pump is a device that delivers insulin to a diabetic patient at regular intervals. It presumably regulates insulin better that standard injections. However, data to establish this point are few, especially in children. The following study was set up to assess the effect of use of the insulin pump on HbgA1c, which is a long term marker of compliance with insulin protocol. In general, a normal range for HgbA1c is < 7%. Data were collected on 256 diabetic...
Norrie sees two lights flash at the same time, then one of them flashes every 4th...
Norrie sees two lights flash at the same time, then one of them flashes every 4th second, and the other flashes every 5th second. How many times do they flash together during a whole minute?
in arduino, having two LED lights, I need to find a way to turn one LED...
in arduino, having two LED lights, I need to find a way to turn one LED with the push of a button, then with a next push of the button turn off the first LED and turn the second LED on. Help with the circuit and code would be appreciated.
Pizzeria Duo Express sells two type of pizzas; regular and deluxe. The company sells each regular...
Pizzeria Duo Express sells two type of pizzas; regular and deluxe. The company sells each regular pizza for $7 and each deluxe pizza for $10. The firm currently has 150 pounds of dough mix and 50 pounds of topping mix. Accounting reports that the current amounts of dough and topping mix have a value of $300 and $125, respectively. Each regular pizza uses 1 pound of dough mix and 4 ounces (16 ounces= 1 pound) of topping mix. Each deluxe...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT