![]() |
|
[challenge] light bulbs - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: [challenge] light bulbs (/Thread-challenge-light-bulbs) |
[challenge] light bulbs - phyrrus9 - 06-21-2015 Rules: Your program may be written in any language of your choice Your program may not take longer than 25 seconds to compute the answer Problem: You have a string of N light bulbs, all of which are turned off. Every second (S), light bulbs that are multiples of S toggle their state (off->on, on->off). After T seconds, what is the state of the light bulb in question (Q)? Inputs: N, T, Q Outputs: state(Q) +1 rep and 50NSP if your program computes the correct result in under 5 seconds. NOTE: a random number generator won't work, I will test each program a random number of times. Limits: 10<N<4,294,967,296 100<T<1,000,000 Q is a 1-bit integer EDIT: PLEASE include an example of how to compile and run if your language is not C/C++/Java. Sorry @Eclipse, lets see how it handles RE: [challenge] light bulbs - phyrrus9 - 06-21-2015 (06-21-2015, 04:58 PM)Eclipse Wrote: Setting a time limit without a specific input is not really logical, since a larger input would make the program's execution time longer. Also, different CPUs will execute shit at different rates. On top of this, different languages are slower/faster than others. Actually, the upper limit is imposed for users to make the same mistake you did at simulating it, but not calculating it. Ran into the same problem when I first did this problem. RE: [challenge] light bulbs - Eclipse - 06-21-2015 (06-21-2015, 06:25 PM)phyrrus9 Wrote: Actually, the upper limit is imposed for users to make the same mistake you did at simulating it, but not calculating it. Ran into the same problem when I first did this problem. Wait, what? Not quite sure what you're getting at. EDIT: By the way, what about my comments on the time limit? RE: [challenge] light bulbs - phyrrus9 - 06-21-2015 (06-21-2015, 07:22 PM)Eclipse Wrote: Wait, what? Not quite sure what you're getting at. The speed isn't really effected by the chosen language, it is but its not an entirely important factor. my code: Spoiler:Code: #include <stdio.h>
int main(int argc, char ** argv)
{
unsigned int T, N, Q, i;
sscanf(argv[1], "%u:%u:%u", &T, &N, &Q);
unsigned int max = T;
register unsigned char state = 0;
for (i = 1; i <= max; i++)
if (i % Q == 0) state = state ? 0 : 1;
printf("T=%d\tQ=%d\tState=%s\n", T, Q,
state ? "On" : "Off");
}Code: gcc -o lights lights.cCode: ./lights T:N:QHere is my results: Code: (precise)phyrrus9@localhost:~$ time ./a.out 543210:4294967295:31
T=543210 Q=31 State=Off
real 0m0.009s
user 0m0.007s
sys 0m0.001sRE: [challenge] light bulbs - Eclipse - 06-21-2015 Windows: 1. https://www.python.org/downloads/ 2. Download 2.7.x 3. Install 4. Open (IDLE) 5. Paste Code 6. Run (F5) Linux: 1. You should have it installed already, if not, google it. 2: Code: python path/to/file.pyRE: [challenge] light bulbs - phyrrus9 - 06-21-2015 (06-21-2015, 09:31 PM)Eclipse Wrote: Windows: ran for 31 seconds until I had to force kill it from memory overconsumption. RE: [challenge] light bulbs - Eclipse - 06-21-2015 (06-21-2015, 09:28 PM)phyrrus9 Wrote: Here is my results: Holy fucking shit. (06-21-2015, 09:37 PM)phyrrus9 Wrote: ran for 31 seconds until I had to force kill it from memory overconsumption. I'm just going to delete it and start again from scratch. Bye. |