Medium riddles

logicmath

The Circular Lake

A swan sits at the center of a perfectly circular lake. At an edge of the lake stands a ravenous monster waiting to devour the swan. The monster can not enter the water, but it will run around the circumference of the lake to try to catch the swan as soon as it reaches the shore. The monster moves at 4 times the speed of the swan, and it will always move in the direction along the shore that brings it closer to the swan the quickest. Both the swan and the the monster can change directions in an instant. The swan knows that if it can reach the lake's shore without the monster right on top of it, it can instantly escape into the surrounding forest. How can the swan succesfully escape?
Assume the radius of the lake is R feet. So the circumference of the lake is (2*pi*R). If the swan swims R/4 feet, (or, put another way, 0.25R feet) straight away from the center of the lake, and then begins swimming in a circle around the center, then it will be able to swim around this circle in the exact same amount of time as the monster will be able to run around the lake's shore (since this inner circle's circumference is 2*pi*(R/4), which is exactly 4 times shorter than the shore's circumference). From this point, the swan can move a millimeter inward toward the lake's center, and begin swimming around the center in a circle from this distance. It is now going around a very slightly smaller circle than it was a moment ago, and thus will be able to swim around this circle FASTER than the monster can run around the shore. The swan can keep swimming around this way, pulling further away each second, until finally it is on the opposite side of its inner circle from where the monster is on the shore. At this point, the swan aims directly toward the closest shore and begins swimming that way. At this point, the swan has to swim [0.75R feet + 1 millimeter] to get to shore. Meanwhile, the monster will have to run R*pi feet (half the circumference of the lake) to get to where the swan is headed. The monster runs four times as fast as the swan, but you can see that it has more than four times as far to run: [0.75R feet + 1 millimeter] * 4 < R*pi [This math could actually be incorrect if R were very very small, but in that case we could just say the swan swam inward even less than a millimeter, and make the math work out correctly.] Because the swan has less than a fourth of the distance to travel as the monster, it will reach the shore before the monster reaches where it is and successfully escape.
90.04 %
42 votes

interviewlogicmath

Burning Rope Problem

A man has two ropes of varying thickness (Those two ropes are not identical, they aren’t the same density nor the same length nor the same width). Each rope burns in 60 minutes. He actually wants to measure 45 mins. How can he measure 45 mins using only these two ropes. He can’t cut the one rope in half because the ropes are non-homogeneous and he can’t be sure how long it will burn.
He will burn one of the rope at both the ends and the second rope at one end. After half an hour, the first one burns completely and at this point of time, he will burn the other end of the second rope so now it will take 15 mins more to completely burn. so total time is 30+15 i.e. 45mins.
90.04 %
42 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
89.81 %
41 votes

funny

Dracula

Dracula’s going to the bank to keep his money, he seems a little more pale than usual, which bank did he go to?
A Blood Bank.
89.81 %
41 votes

funnylogic

Predicting the score of the football game

Joe bets Tony $100 that he can predict the score of the football game before it starts. Tony agrees, but loses the bet. Why did Tony lose the bet?
Joe said the score would be 0-0 and he was right. "Before" any football game starts, the score is always 0-0.
89.58 %
40 votes

logicshort

The rarest book in the World

A man had a book that was worth $40,000. There were only 2 books in existence. He threw it in the furnace, reducing it to a pile of soot. Why did he do this?
He destroyed the book because he has two, and by only having one, the value goes up.
89.58 %
40 votes