Logic Puzzle Answers

by John P. Pratt
last updated 15 Apr 2015

All Puzzles Menu

  1. Brown, Jones and Smith are a doctor, a lawyer, and a teacher. The teacher, who is an only child, earns the least money. Smith, who married Brown's sister, earns more than the lawyer. What is each man's job?

    Smith earns more than the lawyer and also more than the teacher (who earns the least) so Smith must be the doctor. Brown has a sister but the teacher has none, so Brown cannot be the teacher. Hence, because he also is not the doctor, he must be the lawyer. That means Jones must be the teacher because it is the only possibility left.

    One way to solve almost any of this whole class of problems (which can get extremely complicated) is to make a grid with the names in one direction and the occupations in the other. Then one by one eliminate cells in each row or column from the facts given. When all but one of a row or column is filled in, then fill in the rest of the corresponding row and then continue. There are whole books of just these kinds of problems, but once one learns this technique, they can all be solved the same way. I only include one of these problems and this is it. Let's do this problem to see how it works.

    For example, start with the following table:

    DoctorLawyerTeacher
    Brown   
    Jones   
    Smith   

    Then mark an X in impossible cells. Smith cannot be the lawyer, nor the teacher because he makes more money than either of them.

    DoctorLawyerTeacher
    Brown   
    Jones   
    Smith XX

    Then, when only one possible cell remains in a row or column, mark an O there and then fill in the rest of the remaining column or row. That is, once we know that Smith is the doctor, we know that Brown and Jones are not the doctor.

    DoctorLawyerTeacher
    BrownX  
    JonesX  
    SmithOXX

    Now continue crossing off impossible cells. Brown cannot be the teacher because he has a sister and the teacher is an only child:

    DoctorLawyerTeacher
    BrownX X
    JonesX  
    SmithOXX

    Now that only one cell remains possible in both row one and column three, each must be an O.

    DoctorLawyerTeacher
    BrownXOX
    JonesX O
    SmithOXX

    The puzzle is now solved because there is an O in each row and column. If you really feel the need to, you may place an X in the middle cell, but the puzzle is already solved at this point. That is, from the table you can see that Brown is the lawyer, Jones is the teacher, and Smith the doctor. This method might seem like overkill for this simple problem, but once you learn how to draw these grids, you can solve the hard puzzles, like identifying the positions of nine named players on a baseball team.

  2. A farmer has a fox, goose and a bag of grain, and one boat to cross a stream, which is only big enough to take one of the three across with him at a time. If left alone together, the fox would eat the goose and the goose would eat the grain. How can the farmer get all three across the stream?

    Before I try to solve any problem I usually draw a picture and even though I don't here, I did when I solved it (highly recommended). The first trip requires the farmer to take the goose across, because it cannot be left with either grain or the fox. On the next trip, the farmer may take either fox or grain, but then he must bring back the goose. On the third trip, the farmer takes the remaining item, but leaves the goose on the first shore. He then makes a fourth trip to bring the goose. Thus, four trips are required, and the goose ends up crossing three times.

  3. A drawer contains 10 black and 10 brown socks that are all mixed up. What is the fewest number of socks you can take from the drawer without looking and be sure to get a pair of the same color?

    In this problem, it is very important to notice that the color required is not specified. It is only necessary to pick three socks to be guaranteed of getting at least two black or two brown socks.

  4. There are three boxes which each contains two marbles: one has two white, one has two black and one has one white and one black marble. Each of the boxes also is labeled as to its contents, but each label is incorrect. What is the fewest number of marbles you could remove from the boxes and look at in order to definitely determine the contents of all three boxes?

    Solving this problem again involves reading it very carefully and knowing that it means just what it says. We are told exactly what is in each box and also that all three labels are wrong (not just possibly wrong). That is a lot of information, so let's draw a grid as in problem 1, crossing off the possibilities that any box is label correctly:

    Labeled B-BLabeled B-WLabeled W-W
    Contains B-BX  
    Contains B-W X 
    Contains W-W  X

    This problem now differs from the first in that we must choose judiciously to fill in the rest of the table in the fewest number of looks inside the boxes. The best way I know to discover the answer is to look for a choice where you are guaranteed to learn something new. If you look first in the box labeled B-B and you pull out a white marble, you still haven't learned what that box contains because it might be B-W or W-W. Similarly if you look in the W-W box, a choice of B does not allow you even to fill in one more cell of the table. But if you choose the B-W box, then you are guaranteed to be able to fill in one more cell, because if you draw out a white marble, then that box must be the W-W. If you draw out a black, then it must be the B-B. Let's suppose it is white, and fill in the table:

    Labeled B-BLabeled B-WLabeled W-W
    Contains B-BX  
    Contains B-W X 
    Contains W-W OX

    Now we can fill in the rest of column two and row three because only one cell is left:

    Labeled B-BLabeled B-WLabeled W-W
    Contains B-BXX 
    Contains B-W X 
    Contains W-WXOX

    And now, wonder of wonders, the first column only has one empty cell, as does the first row, so we can fill them in too:

    Labeled B-BLabeled B-WLabeled W-W
    Contains B-BXXO
    Contains B-WOX 
    Contains W-WXOX

    So the amazing thing is that by drawing only one marble out of the box labeled B-W, we can deduce what is in all three boxes!

    If we had been bright enough to solve it without the table we could have said that the B-W box must be the W-W because we drew a white marble out of it. That would mean the box labeled B-B must contain the B-W because it is mislabeled and cannot contain two black marbles. That leaves the box labeled W-W to contain two black marbles. Thus, the puzzle can be solved without using a grid, but to me the grid method is more convincing because the logic is so clear at each step.

  5. When asked her 3 children's ages, Mrs. Muddled said that Alice is the youngest unless Bill is, and that if Carl isn't the youngest then Alice is the oldest. Who is the oldest and who is the youngest?

    Again, let's resort to the grid method, because works so well. If you are already getting bored with it, note that every one of these problems introduces a new twist. This one is that Mrs. Muddled is confusing us with statements with the word "unless" in it. How do we mark that in a grid? First, let's set up the grid.

    AliceBillCarl
    Oldest   
    Middle   
    Youngest   

    Okay to start, we are told that the youngest may be either Alice or Bill. How can we use that information? Well, we can deduce that Carl cannot the youngest, so we can cross off that cell:

    AliceBillCarl
    Oldest   
    Middle   
    Youngest  X

    Next we are told that if Carl isn't the youngest (which he's not) the Alice is the oldest. So Alice must be the oldest and we can fill in that box:

    AliceBillCarl
    OldestO  
    Middle   
    Youngest  X

    Now we can fill in the rest of the first column and first row because no one else can be oldest and Alice cannot be anything but oldest:

    AliceBillCarl
    OldestOXX
    MiddleX  
    YoungestX X

    Finally we can fill row three and column three which both have only one remaining cell available:

    AliceBillCarl
    OldestOXX
    MiddleX O
    YoungestXOX

    Thus, Alice is oldest, Carl is Middle and Bill is the youngest.

  6. Two fathers and two sons went fishing. Each caught exactly one fish and yet there were only three fish caught. Why?

    This is a classic in creative thinking. Many problems are set up to get you to expect one thing and then shock you be having the obvious be false. At first we think that two fathers and two sons means four people. But each caught a fish and yet only three fish were caught. Hence, there were only three people. How could that be? It must be that one of the three people fulfills a dual role of being both a father and a son. Is that possible? Of course. So it must have been a grandfather, a father and his son who went fishing.

  7. Mr. and Mrs. Smith and their two children form a typical American family. If exactly two of the following statements are true, what is the first name of the father, mother, son and daughter:

    We could draw a 4x4 grid to solve this but it may not be a great idea because we don't even know which statements are true. Besides, all we need to find out is whether the father is George or Howard, and whether the mother is Dorothy or Virginia. We might be as well off with two 2x2 grids, one for the males and one for the females. But the spirit of this problem is more to determine which statements are true and which false, so let's try doing this one without grids.

    We could try starting with each pair of statements and testing to see whether if two are true, are the others necessarily false. Or we could just guess each of the four answers in turn to see which one works. Because other similar problems might have too many solutions to try, let's do it the first way. The secret to doing the problems with some true and some false statements is to try totally believing a statement and determining whether it leads to a logical contradiction.

    First let's try believing the first two statements to be true and see if that works. Statement #1 means that George and Dorothy are not both parents, #2 means that Howard is that father. So far so good; now we need the last two statements to be false. #3 could be false only if Virginia is the mother, so that would mean Howard and Virginia are the parents. But then #4 would also be true, so this is not the solution because that would be 3 true statements.

    So now let's suppose #1 is false. Then George and Dorothy are the parents. This would mean that #2 is also false because George would be older than his son Howard. Can the last two statements be true? Statement #3 could be true because Virginia could be Howard's younger sister. But, alas, #4 would be false, which is too many false statements.

    Thus we have deduced that #1 must be true and #2 must be false if this puzzle is to have any solution at all. Statement #2 false means that George is that father, and #1 true then means that Virginia is the mother. That is the only possible solution left, so it had better work. Statement #3 must then be false because Virginia must be older than her son Howard. That means #4 needs to be true, and YES, it is: Virginia would be older than her daughter Dorothy. So there is exactly one solution: George and Virginia are the parents of Howard and Dorothy.

  8. Three men were standing in a row, all facing the same direction, so that there was one in back who could see the two in front of him, one in the middle, and one in front who could not see either of the other two. There were three blue and two red hats. One hat was placed on each man, without them seeing which two were left over. Each man was told the total number of each color of hat. First the man in the back was asked if he could deduce what color hat he had on, but he said he couldn't. Neither could the man in the middle, when he was next asked. But then man in the front, who could see neither of those behind him but could hear their answers, correctly deduced by logic what color hat he was wearing. What color was it and why?

    This is one of my all time favorite problems and the one I saw as a child which got me interested on these puzzles. Many people really struggle with it, but it is a totally staightforward problem. The trick is to REALLY put yourself in the place of these men.

    Okay, here goes. Suppose you are the man in the back, could you deduce what color hat you have on by looking at the two in front of you? Well, if they were both red, you would know you had a blue hat on. That man didn't know, and so if we assume he had at least a little sense, we can deduce that the two hats in front were not both red, that is, at least one of them was blue. Most people get this far in the puzzle and are then stumped because they think there is no way to tell which one is blue, or perhaps both. The trick to solving the puzzle is to now put yourself in the place of the second man. If you were in his shoes and heard the first answer, you would also know that at least one of that front two hat was blue. If you saw a red hat in front of you, you would know you had a blue hat. But he did not know. The only thing that could have prevented him from knowing is that the first hat must have been blue.

  9. While a red mark was placed on the forehead of each of three blindfolded women seated facing each other in a circle, they were told that the the mark might be either red or white. Upon removal of the blindfolds, each was to raise her hand if she saw at least one red mark, and then to take it down if she could logically deduce the color of her own mark. All three hands were quickly raised, but then one of them lowered her hand. How did she know?

    This is a variation of the above problem, but very hard for some people to solve. Everyone can see that each woman could be thinking that her own forehead might be red or white because the other two women could be raising their hands because of each other. Again, this is the point where most people stop, and indeed, where the women stopped while all three hands were up. The trick to solving this problem is to REALLY put yourself into the smart woman's shoes. If you REALLY were she, you'd say, either I have a white spot or a red. Suppose you had a white spot. Then the other two women would be looking at one white spot and one red. They would each quickly figure out that that only reason the others hand was up was because of their own red spot. The fact that neither of them figured it out was the tip off to the first that she must also have a red spot. Most people put themselves in the place of the first person, but to solve this one, you must then also put yourself in the place of a second woman.

  10. Albert and Bernard just became friends with Cheryl and they wanted to know her birthday. Cheryl gave them both a list of ten possible dates: May 15, May 16, May 19, June 17, June 18, July 14, July 16, Aug 14, Aug 15, and Aug 17. Cheryl then whispers the month to Albert and the day to Bernard.

    Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know either.

    Bernard: At first I didn't know when Cheryl's birthday is, but after hearing hearing Albert's statement, now I do know.

    Albert: And now I also know when Cheryl's birthday is!

    What is Cheryl's birthday?

    This problem is yet another variation of the above two. To me the way to make this problem easier to do is to really become first Albert and then Bernard and then Albert again and look at the world through their eyes. Pretend you actually know the month or day and then reason from there from the possibilities.

    Albert knows the month. When he says he does not know Cheryl's birthday, that does not tell us anything new because the only way he could know would be if there were a month on the list with only one day.

    When Albert adds that he knows that Bernard could no know that is huge. In what cases might Bernard know? If Bernard had been told 18 or 19 then Bernard would know the birthday because there is only one month on the list with each of those numbers. If Albert knew the month were May or June, then he could not say (honesty is assumed in logic puzzles!) that Bernard could not know. Therefore Albert's statement removes the months of May and June from the possibilities.

    Bernard is clearly smart enough to have also removed May and June from the list of possibilities because now he announces that he knows. What does that tell us? It removes the day 14 from being possible because Bernard wouldn't know in that case because the birthday could be either July 14 or Aug 14. So Bernard must have been told either 15, 16, or 17 and in any of those cases he would know that the birthday for sure. We now know that the birthday is either July 16 or Aug 15 or Aug 17.

    Next we find out that Albert now knows the birthday even though we don't. How could he know? If Albert had been told August, then he would still not know whether it was Aug 15 or Aug 17. He could only know the birthday for sure if he had been told July (remember 14 has been ruled out).

    Therefore, Cheryl's birthday is July 16.

  11. Mr. Reader's five daughters each gave books for Christmas to one or more of her sisters. Each presented four books and each received four books, but no two girls allocated her books in the same way. That is, only one gave two books to one sister and two to another. Beth gave all her books to Alice; Christy gave three to Edith. Which sisters gave the four books to Deborah?

    This sounds like a perfect one for the grid method, but we're going to fill the grid with the number of books given to each sister. Note that it is not required to tell who gave how many books to each sister, but only to Deborah. It may not be solvable all the way, but let's try. First let's make a grid with what is given, with names at left meaning "Gives" and names at top meaning "Receives".

    AliceBethChristyDeborahEdith
    Alice0    
    Beth40   
    Christy  0 3
    Deborah   0 
    Edith    0

    Okay, now what? There are a lot of cells to fill in. How do we start? First, we can see that Alice already received her four, so no other sister gave her any, so we can put zeros in the rest of the first column, and also in the rest of her row. Moreover, we can notice that one sister gave one book to each of her sisters. That sister had to be Alice, because none of the other other sisters could give Alice a book because she had received her four already. Thus we can fill in the first row too:

    AliceBethChristyDeborahEdith
    Alice01111
    Beth40000
    Christy0 0 3
    Deborah0  0 
    Edith0   0

    Now we look at the total in the last row and see that it is already 4. So the last cell in the last row must be zero:

    AliceBethChristyDeborahEdith
    Alice01111
    Beth40000
    Christy0 0 3
    Deborah0  00
    Edith0   0

    Now we come to the problem that we don't know if Christy gave her fourth book to Beth or Deborah, and we need to know that to solve the problem. But there is a way to keep filling in the table other ways. Look at Deborah's books received. She only has one so far and needs to get four and has only two sisters left to give them to her. Thus, she must get one book from one sister and two from the other. But Deborah cannot receive two from Christy, who only has one left to give. So Deborah must receive one from Christy and two from Edith:

    AliceBethChristyDeborahEdith
    Alice01111
    Beth40000
    Christy0 013
    Deborah0  00
    Edith0  20

    Technically we are done at this point because we can say that Deborah received one book from Alice and Christy, and two from Edith. But how can we resist filling in the rest of the table? Clearly Deborah must be the one giving away two books to each of two sisters because there are only two left to give them to. And so Edith must the be sister who split up the books 2-1-1. Thus we can fill in the entire table. Note that each gives four books and each receives four:

    AliceBethChristyDeborahEdith
    Alice01111
    Beth40000
    Christy00013
    Deborah02200
    Edith01120

    Isn't that an astounding amount of information to fill in from so little given? That is why this problem is one of my favorites.

  12. How can you connect nine dots in three straight rows of three with four straight lines without raising the pencil from the paper?

    This calls for a creative answer. It requires going beyond the end of the square of nine dots:

    O------O-------O
    |\            /
    | \          /
    |  \        /
    O   O      O
    |     \   /
    |      \ /
    |       /
    |      / \
    O     O   O
    |    /
    |   /
    |  /
    | /
    |/
    

  13. A man needed to pay his rent and was out of money, but found that his rent was worth about one gold link on his chain per day. What is the fewest number of cuts he can make in his 23-link chain to pay the rent for up to 23 days?

    This problem is great because it requires only two links to be cut. Cut link number 4 and link number 11 counting from the same beginning link. He then has 2 pieces of length 1 (the cut links), and one of 3, 6, and 12. He can then pay the rent as follows. One each of the first two days he can give a cut link. On the third day he gives the chain of 3 and gets his two cut links back. He uses them on days 4 and 5, and then trades all given so far and gives the 6-link chain on day 6. He then again repeats the first steps for days 7-11. On day 12 he gets all those links back and gives the 12-link chain. The then repeats the actions of the first 11 days to go all the way though day 23. For those knowing numbering systems, it will be noticed that this is basically a trinary numbering scheme.

  14. An explorer wishes to cross a barren desert that requires 6 days to cross, but one man can only carry enough food for 4 days. What is the fewest number of other men required to help carry enough food for him to cross?

    There are probably a lot of ways to solve this but my way was first to realize that if each of the men ate his own food then even if we begin with a hundred men, each can only get four days into the desert. Clearly the idea is to get only the one explorer across and have the helpers return back. By simply trying a few ideas the answer is clearly that two other men are required.

    The first helper only goes on day into the desert. He feeds the other two men during the first day, so that at the beginning of the second day, he only has one day rations left. So he goes back to camp. On the second day, the second helper feeds himself and the explorer. On the beginning of the third day the helper now has two days rations left so he heads back. The explorer is two days into the journey and still has all four days of his food left, so he continues on alone.

  15. A traveler meets a native in the jungle at a the fork in the trail, where only one path goes to the village. The traveler does not know which path to take and knows that the native could be either from the tribe of Truth-tellers, who always tell the truth, or from the Liars, who always lie. What is one question he could ask the native to discover the path to the village?

    There are at least a hundred variations on this problem and they are not all based on the same idea. This is one of the simplest but it is still tricky. The idea is to find a question such that either native will answer the same. That requires that the question include some sort of double negative, which will cancel out the fact that he may be lying. One example is "If you were from the other tribe, which path would you say goes to the village?" The truth teller will point to the wrong path, and so will the liar (think about it). So whatever path is pointed to, take the other one.

  16. Twelve billiard balls all weigh the same, except for one that is either light or heavy. Determine in three weighings on a balance scale which is the "odd ball", and whether it is light or heavy.

    What makes this problem hard is the last requirement to tell in every case whether the ball is light or heavy. There are many ways to find the odd-ball, but I only know one way to really do this problem, and it is elegant because in every case but one, the scale could balance or go either way on each weighing. This is my way:

    Weighing 1. Put four on each side of scale. If they balance, it is case A. If not, then B.

    Weighing 2, Case A. Put three of the four unknown (unweighed) balls on one side of scale and 3 of the 8 normal from first weighing on other. If they balance it is case Aa, if not Ab.

    Weighing 3, Case Aa. Put the only unweighed ball on balance with any other (normal) ball. If it goes up, it is light, if down it is heavy. If it balances something is wrong! (This is the one case where it cannot balance).

    Weighing 3, Case Ab. You now know that the odd ball is among the three new ones just weighed, and you already know whether it is light or heavy (depending on if that side of scale went up or down). Weight two of those three against each other. If it balances, the other one is the odd ball. If not, the one that goes in the direction you already know is the odd ball. That is, if you already knew one of the three was light, then the side that went up has the light ball.

    Weighing 2, Case B. Take the four balls from the side of the scale which went down and put two on each side of the scale. Also take two of the four from the side that went up and put on each side of the scale, noting which are which. Now there are three balls on each side of the scale. If it balances, it is case Ba, if not Bb.

    Weighing 3, Case Ba. Now we know that one of the two balls used in the first weighing but not the second is light. Weight either one against any other standard ball. If it goes up it is light, otherwise the other one is.

    Weighing 3, Case Bb. Whichever side went down has two balls that might be heavy, or there could be one light one on the other side. Weight the two possible heavies against each other. If one side goes down, that is the heavy ball. If they balance, then the one the might be light on the other side is indeed light.

  17. A prisoner was given a chance to be blindfolded and pick one ball from two bowls that would contain a total of 50 white and 50 black balls. Choosing white meant freedom, black meant death. He asked if he could divide the balls between the bowls before he was blindfolded and his request was granted. What is the best way to divide the balls between the bowls?

    He asked that all the balls be put in one bowl except one white ball in the other. There was a 1/2 chance of getting the bowl with the white ball, and 100% chance of getting a white ball in that case. Even if he got the other one, he still had a 49/99 chance of life, which is nearly 1/2. Thus the total odds are about 1/2 (if right bowl) + 1/4 (half the time if wrong bowl) = 3/4.

  18. How can three missionaries and three cannibals cross a river in a canoe that holds at most two people, if the cannibals must never outnumber the missionaries on either side?

    This answer is being added to this page on 17 Feb 2007. Before today, I had an additional constraint in the problem that the two cannibals could not cross together. For the answer, I said that it was hard and I'd have to come back to it. Today I came back to it, and it was not only hard, it is easy to show it is impossible, and no one has told me after several years! The only possible first move would be that one missionary and one cannibal cross together, and then the only move would be that the missionary brings the canoe back. Then there is no possible second move! If you saw that and didn't tell me, shame on you. So today I dropped that mistaken constraint and here's an answer:

    Send two cannibals over first and have one bring back the canoe. Then repeat that, and then send two missionaries across and have one bring back a cannibal. Then send both the remaining missionaries over, and have a cannibal return the canoe. Now all the cannibals are on the near side of the river, and the missionaries on the far side. Now just have the cannibals bring the rest over in two trips and you're done.

  19. What is an English word that contains the five vowels a,e,i,o,u in order?

    Someone at work asked me this and I cheat to get the answers by using an electronic dictionary with wildcards. He was thinking of "facetious", an one could even add a "y" in "facetiously" if desired. Other answers include "abstemious", "arsenious," but that's about it unless you allow extra vowels or multiple words. I know this isn't exactly a logic puzzle, but here it is anyway.

  20. The following puzzle is about two actual historial people.

    George and Evelyn never met but they carried on writing until late in life. It has been said that Evelyn loved George, but she was too old for him. George married in 1880. He converted to Catholicism in 1930. During World War II, he served with the Royal Marines. Partly in recognition of this, Evelyn's subsequent writings analyzed the character of that war.

    Evelyn died in 1966 in Somerset. Her first full-length novel had been published in 1859. She is buried in Highgate Cemetery. He died at age 62, after having published his autobiography in 1964. He lived one year longer than she did.

    How could these statements all be true? George was George Elliot, pen name of Mary Ann Evans, who lived from 1819-1880. Evelyn was Evelyn Waugh (1903-1966), a man who was an English author known for his satirical about wealthy London society. They both kept writing books until late in life (not letters to each other). Evelyn loved George means that he loved her books, just as he could have loved Shakespeare. The rest is just a statement of facts, arranged to confuse, hoping the reader would assume the George was male and Evelyn female.

  21. The following is the only puzzle in this list which I created. It was a birthday gift for Brent, my nutty friend who reminds me of a big, rambling bear. Can you find his first, middle and last name spelled out in the verse, using a simple arithmetic code?

    "Dizzy Bear" Brent: neater, no nuttiest
    Brent; rambling,
    Big and ageless.

    The verse in rows separated by three letters.
    His name is Dennis Brent Briggs. If you got Dan Brent Briggs, you did great, but you fell into the trap of accepting a highly probable short first name that was not part of the puzzle before looking at all possible answers. If you had found "Dennis," there would have been no doubt in your mind.

    The verse in rows separated by five letters.
    The first letter of each line and of the first three words form an acrostic, implying that his initial might be DBB. The code is to count forward a fixed number of letters to find a hidden name. For example, begin on the "B" in "Bear" and count forward every three letters. You find that it spells out "Brent." Note in the illustration that it forms a perfect cross, designed to make it clear that it is not there by chance, in order to help you discover the code.

    Now count every 5 letters beginning at the first letter to get "DBrentBriggs." That confirms the suspicion of the first initials, but leaves the first name unknown. Starting with the first "D" you can find the name Dan by counting every seventh letter. But to be thorough you should try all possible counts. Counting every 11th letter yields "Dennis." Because that is a much longer name (and hence improbable to be there by chance), and because it begins and ends on the first and last letter, it should be clear that it is the one the puzzle designer had in mind. Note that even the capitalization of the letters comes out correctly. By the way, these codes are the same as used in the very controversial so-called "Bible Codes," except that those codes can run forward or backward.