Riddle #497

Similar riddles

See also best riddles or new riddles.

logicmath

Flipping Lockers

There are 1 million closed school lockers in a row, labeled 1 through 1,000,000. You first go through and flip every locker open. Then you go through and flip every other locker (locker 2, 4, 6, etc...). When you're done, all the even-numbered lockers are closed. You then go through and flip every third locker (3, 6, 9, etc...). "Flipping" mean you open it if it's closed, and close it if it's open. For example, as you go through this time, you close locker 3 (because it was still open after the previous run through), but you open locker 6, since you had closed it in the previous run through. Then you go through and flip every fourth locker (4, 8, 12, etc...), then every fifth locker (5, 10, 15, etc...), then every sixth locker (6, 12, 18, etc...) and so on. At the end, you're going through and flipping every 999,998th locker (which is just locker 999,998), then every 999,999th locker (which is just locker 999,999), and finally, every 1,000,000th locker (which is just locker 1,000,000). At the end of this, is locker 1,000,000 open or closed?
Locker 1,000,000 will be open. If you think about it, the number of times that each locker is flipped is equal to the number of factors it has. For example, locker 12 has factors 1, 2, 3, 4, 6, and 12, and will thus be flipped 6 times (it will end be flipped when you flip every one, every 2nd, every 3rd, every 4th, every 6th, and every 12th locker). It will end up closed, since flipping an even number of times will return it to its starting position. You can see that if a locker number has an even number of factors, it will end up closed. If it has an odd number of factors, it will end up open. As it turns out, the only types of numbers that have an odd number of factors are squares. This is because factors come in pairs, and for squares, one of those pairs is the square root, which is duplicated and thus doesn't count twice as a factor. For example, 12's factors are 1 x 12, 2 x 6, and 3 x 4 (6 total factors). On the other hand, 16's factors are 1 x 16, 2 x 8, and 4 x 4 (5 total factors). So lockers 1, 4, 9, 16, 25, etc... will all be open. Since 1,000,000 is a square number (1000 x 1000), it will be open as well.
94.48 %
46 votes

mathshort

How many times do a clock's hands overlap

How many times do a clock's hands overlap in a day ?
22 times. am 12:00 1:05 2:11 3:16 4:22 5:27 6:33 7:38 8:44 9:49 10:55 pm 12:00 1:05 2:11 3:16 4:22 5:27 6:33 7:38 8:44 9:49 10:55
93.98 %
42 votes

cleanlogicshort

Brown house

In a one storey brown house, there was a brown person with a brown computer, brown telephone, and brown chair. He also had a brown cat and a brown fish – Just about everything was brown – What colour was the stairs?
As it was a one-storey house – there were no stairs.
93.84 %
41 votes

logicmath

Anagram Checker

Two words are anagrams if and only if they contain the exact same letters with the exact same frequency (for example, "name" and "mean" are anagrams, but "red" and "deer" are not). Given two strings S1 and S2, which each only contain the lowercase letters a through z, write a program to determine if S1 and S2 are anagrams. The program must have a running time of O(n + m), where n and m are the lengths of S1 and S2, respectively, and it must have O(1) (constant) space usage.
First create an array A of length 26, representing the counts of each letter of the alphabet, with each value initialized to 0. Iterate through each character in S1 and add 1 to the corresponding entry in A. Once this iteration is complete, A will contain the counts for the letters in S1. Then, iterate through each character in S2, and subtract 1 from each corresponding entry in A. Now, if the each entry in A is 0, then S1 and S2 are anagrams; otherwise, S1 and S2 aren't anagrams. Here is pseudocode for the procedure that was described: def areAnagrams(S1, S2) A = new Array(26) A.initializeValues(0) for each character in S1 arrayIndex = mapCharacterToNumber(character) //maps "a" to 0, "b" to 1, "c" to 2, etc... A[arrayIndex] += 1 end for each character in S2 arrayIndex = mapCharacterToNumber(character) A[arrayIndex] -= 1 end for (i = 0; i < 26; i++) if A[i] != 0 return false end end return true end
93.70 %
40 votes

logicshort

Akbar and Birbal

One day, Emperor Akbar posed a question to Birbal. He asked him what Birbal would choose if he offered either justice or a gold coin. "The gold coin," said Birbal without hesitation. On hearing this, Akbar was taken aback. "You would prefer a gold coin to justice?" he asked, not believing his own ears. "Yes," said Birbal. The other courtiers were amazed by Birbal's display of idiocy. They were full of glee that Birbal had finally managed himself to do what these courtiers had not been able to do for a long time - discredit Birbal in the emperor's eyes! "I would have been disappointed if this was the choice made even by my lowliest of servants," continued the emperor. "But coming from you it's not only disappointing, but shocking and sad. I did not know you were so debased!" How did Birbal justify his answer to the enraged and hurt Emperor?
"One asks for what one does not have, Your Majesty." said Birbal, smiling gently and in quiet tones. "Under Your Majesty´s rule, justice is available to everybody. But I am a spendthrift and always short of money and therefore I said I would choose the gold coin." The answer immensely pleased the emperor and respect for Birbal was once again restored in the emperor's eyes.
93.70 %
40 votes

logicshort

A boys name

Without looking at a calendar, within a minute name a boys name using 5 consecutive first letters of 5 consecutive months.
JASON - July August September October November.
93.55 %
39 votes

logicmath

Three daughters

Sam has got three daughters. The eldest daughter is the most honest girl in the universe and she always speaks truth. The middle daughter is a modest woman. She speaks truth and lies according to the situations. The youngest one never speaks truth. Not a single word she spoke was true and would never be true. Sam brought a marriage proposal for one of his girls. It was John. John wanted to marry either the eldest or the youngest daughter of Sam as he can easily identify whether the girl speaks truth or lie! John told his desire to Sam. However, Sam laid a condition. He told John that he will not say who the eldest, middle or youngest one is. Also, he allowed john to ask only one question to identify the eldest or youngest so he can marry one. John asked one question and found the right girl. What was the question and whom should he pick? He asks this question to one of the daughters. If he asked this question to older daughter pointing at other two, he probably would know the youngest one! NO matter, she always speaks truth. If he asked the question to middle one, probably he can choose either. If he asked the youngest one, she always lies and he can find eldest one! No matter, he has to choose the youngest one based on the answer.
The question he asked is, ‘Is she older than her!’ He asks this question to one of the daughters. If he asked this question to older daughter pointing at other two, he probably would know the youngest one! NO matter, she always speaks truth. If he asked the question to middle one, probably he can choose either. If he asked the youngest one, she always lies and he can find eldest one. No matter, he has to choose the youngest one based on the answer.
93.39 %
38 votes

logicmathshort

Leave 6

Take 9 from 6, 10 from 9, 50 from 40 and leave 6. How is it possible?
SIX - 9 (IX) = S 9 (IX) - 10 (X) = I 40 (XL) - 50 (L) = X
93.39 %
38 votes