Math riddles

logicmath

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
71.88 %
55 votes
mathcleansimplelogic

Count the number of times the letter "F" appears in the following paragraph: FAY FRIED FIFTY POUNDS OF SALTED FISH AND THREE POUNDS OF DRY FENNEL FOR DINNER FOR FORTY MEMBERS OF HER FATHER'S FAMILY.
It appears 14 times. Make sure to count the "F"s in the word "OF", which people commonly miss.
71.53 %
50 votes
logicmathclever

Dean Sam and Castiel are three brothers. Interestingly their current age is prime. What's more interesting that difference between their ages is also prime. How old are they?
Sam : 2 Dean : 5 Castiel : 7 Age diff 7 - 2 = '5' is prime 7 - 5 = '2' is prime 5 - 2 = '3' is prime
71.50 %
71 votes
logicmathtricky

A train leaves from Halifax, Nova Scotia heading towards Vancouver, British Columbia at 120 km/h. Three hours later, a train leaves Vancouver heading towards Halifax at 180 km/h. Assume there's exactly 6000 kilometers between Vancouver and Halifax. When they meet, which train is closer to Halifax?
Both trains would be at the same spot when they meet therefore they are both equally close to Halifax.
71.12 %
70 votes
logicmathtricky

How can you divide a pizza into 8 equal slices using only 3 straight cuts?
Cut 1: Cut the pizza straight down the middle into two halves. Cut 2: Keeping the two halves in the place, cut the pizza straight down the middle at right angles to the first cut (you will be left with 4 equal quarters) Cut 3: Pile the 4 quarters on top of each other and cut through the middle of the pile. You will be left with 8 equal slices.
71.09 %
74 votes
logicmath

There is a box full of marbles, all but two are blue, all but two are green, and all but two are red. How many marbles are in the box?
There are 3 marbles (1 blue, 1 green, and 1 red).
67.91 %
102 votes
logicmathsimpleclean

In a new Engineering Hostels they have 100 rooms. Ankit Garg was hired to paint the numbers 1 to 100 on the doors. How many times will Ankit have to paint the number eight ?
20 times. (8, 18, 28, 38, 48, 58, 68, 78, 98, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89)
67.57 %
69 votes
logicmathcleansimple

In a supermarket, the first 25 customers of the day purchased an average of two items each. After a further 15 customers, the average number of items purchased by each customer rose to eight. What was the average number of items purchased by the last 15 customers only?
((15+25) x 8 - (25 x 2))/15 = 18
67.34 %
43 votes
<< < 1011
MORE RIDDLES >
Page 10 of 11.