Classic logic questions in software testing

Question 1: it takes 1 hour to burn an uneven rope from head to tail. Now there are several ropes of the same material. How to use the method of burning the rope to time 1 hour and 15 minutes?

Now take three different ropes. A Rope, B Rope, C Rope Step 1: A The rope burns from both ends at the same time B Burn a rope. 30 minutes later A It's over. It takes 30 minutes to burn Step 2: A After burning, at the same time B The other end of the rope is also ignited. Start burning at both ends. It takes 15 minutes to finish burning Step 3: take another one C Burn the rope from both ends for 30 minutes 30+15+30=75 ，The three steps add up to 1 hour and 15 minutes

Question 2: there are five students doing homework in the classroom. Today, there are only four homework subjects: mathematics, English, Chinese and geography. Verification: at least two of the five students are doing the same homework

Proof: treat 5 students as 5 apples Mathematics, English, Chinese and geography homework are regarded as one drawer, with a total of 4 drawers According to the drawer principle, there must be a drawer in which there are at least two apples That is, at least two students are doing homework in the same subject

Question 3: if there is an infinite amount of water, a 3-liter bucket and a 5-liter bucket, and the shapes of the two buckets are uneven up and down, how can we accurately weigh 4 liters of water?

Fill the bucket with 5-liter bucket and pour it into 3-liter bucket. After filling, there are 2 liters left in the bucket Empty the three liter bucket and pour the two liters into the three liter bucket Fill the bucket with 5 liters, pour it into 3 liters, pour it into one liter, and the rest in the bucket is 4 liters

Question 4: a fork in the road leads to the country of honesty and the country of lying. Two people came. It is known that one is from the honest country and the other is from the lying country. An honest country always tells the truth, and a lying country always lies. Now you're going to lie country, but you don't know which way to go. You need to ask these two people. How should I ask?

Ask one of them: which way would the other say is to the country of honesty? The road that the respondent pointed to must be to the lying country

Question 5: 12 balls and a balance. Now we know that only one is different from other weights. How to weigh it to find the ball three times (note that this question does not indicate whether the weight of the ball is light or heavy)

Divided into three groups:Four in each group,First group number 1-4，Group II 5-8，Group 3 9-12 First weighing: put the first group on the left and the second group on the right ==A The first possibility==: Balance. The difference is in the third group Next, you can put numbers 9, 10 and 11 on the left and numbers 1, 2 and 3 on the right a.If it is balanced, No. 12 is different b.If the left is heavy and the right is light, the difference is in No. 9, 10 and 11, and it is heavier than the normal ball. Weigh again: 9 on the left and 10 on the right. If it is balanced, No. 11 is different; If the left is heavy and the right is light, then No. 9 is different. If the right is heavy and the left is light, then No. 10 is different c.If the left is light and the right is heavy, the reason is the same b ==B The second possibility==: If the left is heavy and the right is light, the difference is 1-8 Medium, but I don't know whether it's lighter or heavier than normal. The second weighing: put numbers 1, 2 and 5 on the left and numbers 6, 9 and 3 on the right. a.If balance. The difference is in 4, 7 and 8. It can be called the third time: 4 and 7 on the left and 9 and 10 on the right. If balanced, then 8 is different;If the left is heavy and the right is light, then 4 is different; If the left is light and the right is heavy, then 7 is different. b.Still heavy on the left and light on the right. The different ones are in 1, 2 and 6 whose positions have not changed. It can be called the third time: put 1 and 6 on the left and 9 and 10 on the right. If balanced, then 2 is different; If the left is heavy and the right is light, then 1 is different;If the left is light and the right is heavy, then 6 is different. c: Light on the left and heavy on the right. The difference is in 5, 3 and 4, because only they change the original position. It can be called the third time: put 5 and 3 on the left and 9 and 10 on the right. If the left is light and the right is heavy, then 5 is different. If the left is heavy and the right is light, then 3 is different. ==C The third possibility==: Light on the left and heavy on the right, the same reason B

Question 6: there are two prisoners in a cell. Every day, the prison will provide this cell with a pot of soup for the two prisoners to share. At first, the two people often had disputes because some of them always thought the other party had more soup than themselves. Later, they found a way to have the best of both worlds: one person divided the soup and let the other choose first. So the dispute was settled. However, now a new prisoner has been added to this cell. Now three people share the soup. A new way must be found to maintain peace between them. What should I do

First let a divide the soup, and then B and C pick the soup for themselves in any order, and leave the remaining bowl to a. In this way, the sum of B and C must be the biggest they can get. Then mix their soup and divide it again according to their method

Question 7: there are five houses in a row. All houses have different appearance colors. All homeowners come from different countries and all homeowners have different pets; Drink different drinks; Tips for smoking different cigarettes:

The British live in a red house, the Swedes have a dog, the Danes drink tea, the green house is on the left of the White House, the owner of the green house drinks coffee, the owner of the house who smokes pall mall cigarettes keeps birds, the Yellow owner smokes dunhill, the owner in the middle drinks milk, the Norwegians live in the first house, and the person who smokes blend lives next door to the cat house, The owners of horses smoke next door to Dunhill's house, the owners of blue master drink beer, the Germans smoke prince, the Norwegians live next door to the blue house, and the people who only drink boiled water live next door to blend,

Q: who keeps fish

Problem solving process: (1)The owner in the middle drinks milk: it can be concluded that the owner of the third house drinks milk (2)Norwegians live in the first house: it can be concluded that the nationality of the owner of the first house is Norwegian (3)Norwegians live next door to the blue house: it can be concluded that the owner of the second house is blue (4)The green house is on the left of the White House; The owner of the green house drinks coffee: because the green house and the White House are connected together, the color of the house you can choose now is No. 3, 4 and 5. The green house and the White House are in these three houses; The green house is on the left of the White House. Therefore, if No. 3 is green, No. 4 is white. If No. 4 is green, No. 5 is white. Because the owner of the green house drinks coffee, the green house cannot be No. 3. Therefore, No. 4 is green and No. 5 is white; The owner of the fourth house drinks coffee (5)British people live in red houses: House 1 is Norwegian, so house 1 is excluded. Houses 2, 4 and 5 have colors. Therefore, house 3 is red and its nationality is British (6)Yellow Homeowner Dunhill: The color of the remaining No. 1 house is yellow, and the owner smokes it Dunhill (7)The horse owner is smoking Dunhill Next door: smoking Dunhill It's No. 1, so no. 2 keeps horses (8)Draw Blue Master The owner of the house drinks beer: now the drinks and cigarettes are not determined to be No. 2 and No. 5; Hypothesis: if No. 5 is, the owner of House No. 5 and beer, smoke Blue Master (9)On the premise that (8) is true, Danes drink tea: No. 2 is the only one whose nationality and drink are not determined. Therefore, the nationality of the owner of No. 2 is Danes and drinks tea (10)Under the premise of (8) hypothesis, the Germans draw Prince: Nationality is not fixed on the 4th and 5th, while the 5th is drawn Blue Master，Therefore, the owner of House No. 4 is German, so smoke Prince (11)Under the premise of hypothesis (8), the Swede has a dog: only No. 5 is left. Therefore, the owner of No. 5 is Swedish and has a dog (12)On the premise of (8) hypothesis, draw Pall Mall The owner of cigarettes keeps birds: No. 3 is the only one without cigarettes and pets. Therefore, the owner of No. 3 smokes Pall Mall，keep pet (13)On the premise of (8) hypothesis, draw Blend Of people live next door to the cat house: there is only No. 2 left, so the owner of No. 2 smokes Blend，1 House owner keeps cats (14)Under the premise of (8) hypothesis, people who only drink boiled water live in the house where they smoke Blend Next door: only No. 1 is left. The owner of No. 1 drinks boiled water (15)The last one left is fish farming (16)Therefore, (8) hypothesis holds

Question 8: a manager has three daughters. The sum of the ages of the three daughters equals 13. The multiplication of the ages of the three daughters equals the age of the manager. A subordinate knows the age of the manager but does not know the age of the three daughters. The manager said that only one daughter has black hair How old are the three daughters? Why?

[Set the age of the three sisters as a,b,c,be a+b+c=13,Regardless of the manager's age,So you can list all the combinations of the ages of the three sisters: (a total of 14 combinations) 1,1,11 1,2,10 1,3,9 1,4,8 1,5,7 1,6,6 2,2,9 2,3,8 2,4,7 2,5,6 3,3,7 3,4,6 3,5,5 4,4,5 Then multiply,So the possibility of getting the age of the manager is: 11,20,27,32,35,36,36,40,56,60,42,72,75,80, Then infer according to normal logic,Except 1,6,6 And 2,2,9 All the managers are over 36 years old,The age of the manager obtained by other combinations is unrealistic,So the following analysis 1,6,6 And 2,2,9 These two combinations,Because only one daughter has black hair,Understanding of black hair,We can think of a child as fetal hair at the age of 1,Not black hair,So exclude 1,6,6(Because 1-year-old is not black hair,So two 6-year-olds must be twins,Black together),So only 2,2,9 Meet the conditions

Question 9: there is a bottle of poison in 1000 bottles. A mouse will die within a week after eating the poison. If you want to detect a bottle of poison within a week, how many mice do you need at least?

[According to 2^10=1024，So 10 mice can determine which of 1000 bottles is poisonous. The specific implementation is the same as the principle that three mice determine eight bottles. 000=0 001=1 010=2 011=3 100=4 101=5 110=6 111=7 One represents a mouse, 0-7 Represents 8 bottles. That is to say, the drugs in bottles 1, 3, 5 and 7 are mixed for rat 1 to eat, the drugs in bottles 2, 3, 6 and 7 are mixed for rat 2 to eat, and the drugs in bottles 4, 5, 6 and 7 are mixed for rat 3 to eat. Which mouse dies, the corresponding bit mark is 1. If mouse 1 is dead, mouse 2 is not dead, and mouse 3 is dead, then it is 101=5 Bottle is poisonous. In the same way, 10 mice can determine 1000 bottles]

Question 10: there are three tasks: sweeping the floor, cleaning the windows and mopping the floor. It takes 30 minutes to complete each task. There are two people. Each person can only do one job at the same time. How long does it take to complete the three tasks at the fastest?

45 Minutes( A Sweep the floor for 15 minutes, then A Clean the windows for another 30 minutes, B Mop the floor for 30 minutes, then sweep the floor for 15 minutes)

Question 11: a businessman rode a donkey through a 1000 kilometer long desert to sell 3000 carrots. It is known that a donkey can carry 1000 carrots at one time, but it has to eat one carrot every kilometer. Q: how many carrots can merchants sell?

The merchant took the donkey with 1000 carrots and walked 250 kilometers first. At this time, the donkey had eaten 250 carrots, Put down 500, return in place and eat another 250. The merchant took another 1000 carrots with the donkey and walked to 250km. At this time, the donkey had eaten 250 carrots, loaded 250 of the original 500 carrots and continued to move on to 500km. At this time, the donkey ate another 250 carrots, put down 500 carrots, and the remaining 250 carrots returned to 250km, After 250 kilometers on the pack, the remaining 250 returned to the original place. At this time, the donkey ate another 250. The merchant then took the donkey to pack 1000 carrots and walked 500 kilometers. At this time, the donkey had eaten 500 carrots and carried the original 500 carrots. Out of the desert, the donkey ate 500 carrots and there were 500 left

Question 12:

1

1 1

2 1

1 2 1 1

1 1 1 2 2 1

What's next?

Answer: 312211 Analysis: the next line is the explanation of the previous line. For example, the second line is the explanation. The first line: one 1 The third line is to explain the second line, two 1s The fourth line is to explain the third line: 1 2 1 1 The fifth line is to explain the fourth line: 1 1 2 2 1 Therefore, it is inferred that the sixth line is to explain the fifth line: 3 1 2 2 1 1 ——>312211

Question 13: card guessing

Mr. S, Mr. P and Mr. Q know that there are 16 playing cards in the drawer of the table:

Hearts A, Q, 4

Spade J, 8, 4, 2, 7, 3

Grass flower K, Q, 5, 4, 6

Block A, 5

Professor John picked out one of the 16 cards and told Mr. p the number of points and Mr. Q the color of the card. At this time, Professor John asked Mr. P and Mr. Q: can you infer what card this card is from the known points or colors? So Mr. S heard the following conversation:

Mr. P: I don't know this card

Mr. Q: I know you don't know this card

Mr. P: now I know this card

Mr. Q: I know

After listening to the above dialogue, Mr. S thought about it and correctly introduced what card this card is

What is this card, please

Square slice 5 P If you know the number of points but don't know the design and color, you can't judge the card, which means that the number of points is more than one card, and the number of points may be 4, Q, A. 5. By number of points, 4 hearts, 4 spades, 4 flowers; heart Q， Grass flower Q； heart A， block A； Grass flower 5, square 5. For ease of understanding, it is arranged according to the design and color, i.e Spade 4 Hearts, 4, hearts Q， heart A CaoHua 4, CaoHua 5, CaoHua Q block A， Box 5. Q know P I don't know. It means that all the cards of this suit are repeated. Get it immediately block A ， Block 5 heart A， heart Q ，Hearts 4 P Say, I know now. Indicates that the number of points is unique, Diamonds 5, hearts Q ， Hearts 4 Q Say, I know. It shows that the design and color are unique, Get square piece 5.

Question 14: a man bought a chicken for 8 yuan and sold it for 9 yuan. Then he thought it was not cost-effective. He bought it back for 10 yuan and sold it to another person for 11 yuan. Ask him how much he made?

Direct profit, First deal, 9－8 =1 Second transaction, 11－10 =1 Opportunity cost, 11－8 = 3 So this person lost 1 yuan