Best riddles

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

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.
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

cleanlogicshort

One word

Re-arrange the letters, O O U S W T D N E J R to spell just one word.
"Just one word".
89.81 %
41 votes

logicshort

Country hidden in the paragraph

What country is hidden in the paragraph below? As defendants, we deny all involvement in the unscrupulous dealings which have come to light in the recent government investigation.
Sweden.
89.81 %
41 votes

cleanshort

Six faces

What has six faces, but does not wear makeup. It also has twenty-one eyes, but cannot see?
A die (dice).
89.81 %
41 votes

funny

Superior mother

A man came to visit at a convent while the superior mother was out of town. He left before she returned, and was careful to leave nothing behind. The nuns said nothing about his visit, so how did the superior mother figure out that a man had been there?
Because a toilet seat was up.
89.81 %
41 votes

logic

10 Cigarette butts

Bruce is an inmate at a large prison, and like most of the other prisoners, he smokes cigarettes. During his time in the prison, Bruce finds that if he has 3 cigarette butts, he can cram them together and turn them into 1 full cigarette. Whenever he smokes a cigarette, it turns into a cigarette butt. One day, Bruce is in his cell talking to one of his cellmates, Steve. "I really want to smoke 5 cigarettes today, but all I have are these 10 cigarette butts," Bruce tells Steve. "I'm not sure that will be enough." "Why don't you borrow some of Tom's cigarette butts?" asks Steve, pointing over to a small pile of cigarette butts on the bed of their third cellmate, Tom, who is out for the day on a community service project. "I can't," Bruce says. "Tom always counts exactly how many cigarette butts are in his pile, and he'd probably kill me if he noticed that I had taken any." However, after thinking for a while, Bruce figures out a way that he can smoke 5 cigarettes without angering Tom. What is his plan?
Bruce takes 9 of his 10 cigarette butts and turns them into 3 cigarettes total (remember, 3 cigarette butts can be turned into 1 cigarette). He smokes all three of these, and now he has 4 cigarette butts. He then turns 3 of the 4 cigarette butts into another cigarette and smokes it. He has now smoked 4 cigarettes and has 2 cigarette butts. For the final step, he goes and borrows one of Tom's cigarette butts. With this cigarette butt plus the 2 he already has, he is able to make his 5th cigarette to smoke. After smoking it, he is left with 1 cigarette butt, which he puts back in Tom's pile so that Tom won't find anything missing.
89.81 %
41 votes

short

If I drink, I die

If I drink, I die. If i eat, I am fine. What am I?
Fire.
89.81 %
41 votes