Setup
A number (n) of lamps are placed in a line, some are switched on and some are off. Write a function that will return the smallest ...
For further actions, you may consider blocking this person and/or reporting abuse
A Common Lisp implementation 😊.
Correct solution:
This solution is wrong, I'll change it and put the new corrected one of the top. I misunderstood the problem statement the first time.
the first test shouldn't be 6?
1 0 0 1 0 1 0 0 1 0 1
0 1 0 1 0 1 0 1 0 1 0
(alternated)x x - - - - - x x x x
What I've understood from the problem statement is that both converting everything to 0s and converting everything to 1s are valid answers, and you need to choose the fastest one (less changes needed).
For the
1 0 0 1 0 1 0 0 1 0 1
Maybe I understood it wrong :( Definetely, I understood it wrong. I'll change it :D.
I don't know, i think that you understood it right your solution makes sense, the way that i imagine there is no way to get the "less changes needed" because i'll switch everything to see if it it's alternated
I though the solution was to count the number of changes to light everything on or off. But the idea is to find out the number of changes for alternate lights, so the solution there is wrong :(.
I just changed the original post to add the new solution.
Now that I read the comments, I think Kevin is right, but I understood it from the point of view of Rafael. But it makes sense since they need to alternate, not to start with 0 (switched off) everytime.
Rust:
Javascript
Python:
A variation on the javascript solution. Opted for a bit more verbosity for ease of understanding. Would love feedback as I get my coding skills back into shape.
Elm
Demo.
Standard ML of New Jersey