It dosn't even state if the lamps are on or off to begin with, so I asume they're off?Egzon Krasniqi wrote:[color=black]
...
No.1 enters the room, changes the condition of each lamp and leaves the room
...
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
It says the lamps are all turned off before the exercise.Daniel Demesmaecker wrote:. . . It dosn't even state if the lamps are on or off to begin with . . .
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
There are three kinds of actuaries: those who can count, and those who can't.
Daniel Demesmaecker wrote:
It dosn't even state if the lamps are on or off to begin with, so I asume they're off?Egzon Krasniqi wrote:[color=black]
...
No.1 enters the room, changes the condition of each lamp and leaves the room
...
If I would just give you the code, the mods would shoot me, but I'll give you this pointer, you'll need a nested for loop, one to represent the persons and one to itterate the lamps.
Daniel Demesmaecker wrote:It dosn't even state if the lamps are on or off to begin with, so I asume they're off?
In a long room are 100 bulbs (lamps) lined up one after the other. Each bulb (lamp) has a breaker("Interlocking" (ON/OFF) which is turned off at the beginning.
Egzon Krasniqi wrote:Can you slove it or not ?
There are three kinds of actuaries: those who can count, and those who can't.
Do you have the code to do this much?Egzon Krasniqi wrote:Lamps in the ROOM are OFF at the beginning.
If you make an boolean array at the start all are FALSE (off);
Carey Brown wrote:
Do you have the code to do this much?Egzon Krasniqi wrote:Lamps in the ROOM are OFF at the beginning.
If you make an boolean array at the start all are FALSE (off);
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:I haven't even read the could, but I already can tell you this, if you would turn in this code at my professir, he would flunk you for sure. Just alone by the way it's formatted, and on first look, it seems way to mutch ocde for what you were trying to do
Daniel Demesmaecker wrote:
if((j+1) % (i+1) == 0){
that can never be true...
And that's only one of the many issues.
you need a nested for loop to itterate the lamp and the persons, 1 int for the interval and a final foreach to print the state of the lamps at the end, that's it...
Surely that is 3, 6, 9....Egzon Krasniqi wrote:. . . Person number 3 enter the ROOM and switch OFF lamps 3 , 5 , 7... . . .
I can tell you. It isn't correct. Not even if it gives the same result as I found this morning is it correct.. . . can someone tell me is this right ? . . .
Are you sure about that? When i is 2 and j is 5, even?Daniel Demesmaecker wrote:
if((j+1) % (i+1) == 0){
that can never be true... . . .
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
I was at school with Lol, but I haven't seen him for a long time. But I am not called Lol myself, so please avoid that word. Also please be careful when editing posts.Daniel Demesmaecker wrote:Lol no I was just editting my post
Campbell Ritchie wrote:
Surely that is 3, 6, 9....Egzon Krasniqi wrote:. . . Person number 3 enter the ROOM and switch OFF lamps 3 , 5 , 7... . . .
I can tell you. It isn't correct. Not even if it gives the same result as I found this morning is it correct.. . . can someone tell me is this right ? . . .
The error is in the line with % in. After that line, any correct results are there by luck, not good programming.
There are also design and style problems.1: Everything is crammed into the main() method, which is far too long. 2: Never use == true and == false; they are poor style and very error‑prone. 3: Don't switch booleans with an if‑else. Use lamps[j] = !lamps[j]; 4: There is no need to copy numbers into a second array; you can traverse the first array and print the results from that.
Egzon Krasniqi wrote: i will try it in my own way i just need the answer "how much lamps are ON at the end" to test my code if its right ?
That's a pleasureEgzon Krasniqi wrote:. . . Thanks for advices man
Afraid not. The fact that you get the right answer doesn't mean that your algorithm is correct. Many people think that. . . i just need the answer "how much lamps are ON at the end" to test my code if its right ?
Show how many of the lamps are (ON) after the 100th person has gone through the room.And whitch lamps are (ON) with numbers ?
Liutauras Vilda wrote:
Egzon Krasniqi wrote: i will try it in my own way i just need the answer "how much lamps are ON at the end" to test my code if its right ?
Please write the code and post it here, so somebody could run it and verify its correctness (or not).
But in general I think, that if you'd understand the problem, you wouldn't question your algorithm whether it is correct or not. To me seems that you didn't spend enough time trying to understand the problem. And that is really the crucial part in any problem.
Campbell Ritchie wrote:Please post what you have, even if it isn't complete.
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|