This is a problem our 5th grader came home with today: tag @Nathalie
There are 1000 lockers in a high school with 1000 students. The
problem begins with the first student opening all 1000 lockers; next
the second student closes lockers 2,4,6,8,10 and so on to locker 1000;
the third student changes the state (opens lockers closed, closes
lockers open) on lockers 3,6,9,12,15 and so on; the fourth student
changes the state of lockers 4,8,12,16 and so on. This goes on until
every student has had a turn.
When all 1,000 students have finished, which locker doors are open?
Can you solve it in Alteryx? I solved it in 4 tools - so don't overthink it. The answer has a cool surpise twist. Post your solution - I'll post mine in a few days if no one else does the identical solution.
Solved! Go to Solution.
Perhaps 5th graders should get an Alteryx license to do their homework with?
Fun problem! I didn't see an easy way to solve it using only 4 tools (at least without using knowledge of the "surprise twist"), so I'm looking forward to seeing your solution @Ned!
I cheated and asked Google. I used 3 tools. @Ned will point out I could have done it in a single tool. Clearly I am not smarter than a 5th grader!
31 is the answer (I hope)!
If the lockers start closed, then an even number of actions means that the locker door is closed. An odd number of actions means that the locker is open. I divide the locker # by the student # and if it is evenly divisible, then I set the action (for that student) to 1. I'll check the sum of actions on all lockers and filter for the ODD locker action counts. These are the 31 open lockers.
This might not be the most elegant way to solve the problem, but it works.
Ok. Now that I know that the result is the perfect squares between 1 & 1,000. Here is a 2 tool solution (plus an unnecessary browse in version 10). I generate 1,000 rows and then compare the SQUARE ROOT of the [Locker] as just the integer without any decimal places (see floor function) to the actual SQUARE ROOT. Only if the two are equal (e.g. 3*3 = 9) is the locker open. 31 Open Lockers. Time to sleep now.
I would have thought we weren't done until we got @chris_love to respond, but I guess it was not to be... ;-)
@jdunkerley79 - this is almost exactly my solution - to the point I won't even bother posting mine. The two generate rows tools exactly reflect the question of each locker change of state, so then its just a matter of seeing summing the flips and testing if it was an even or odd number. It is amusing how many ways there are to detect an even or odd number. MOD(Count,2)!=0, used by a few people; me being a low level programmer and thinking of bits is BinaryAnd(Count,1).
I would not have come up with the POW(-1, COUNT)<0, but it is clearly obvious to math/stats people.
As several people have noted, the answers end up being all the square numbers. The reason is that all factors come in pairs and the locker is opened and then closed again, except when the same number is a factor twice, then it has 1 extra open. Once you understand this, its easy to generate to sequence of open lockers in a single GenerateRows tool, but I do consider it cheating, since it is using a known solution to find a simpler solution. Anyway, my 1 tool answer is attached.
Sorry I'm late, been locked away trying to solve this. I missed the comment you could do it in 4....it took me 1001
Here's the start of my module showing the lockers, the test fails when they're left open
Here's the output log showing which are open:
I've attached my module too. Hope you liked my different way of doing things.