What code goes to the question mark?

You can get a hint
1) Two trains pass

In the old days when single track was still customary, two trains met at the spot of a side track. The track was long enough to hold 1 engine and 4 wagons or 5 wagons. That corresponded with every day traffic, but yesterday was a strike and now both trains pull 8 wagons.
An extra complication is a not-so-strong bridge at the right end of the side track, which no engine may pass, though it is strong enough for normal wagons.
Both engines can both push and pull wagons with their front- and rear ends.
If both a stop and a reversal of direction of an engine counts as 1 move, what is the minimum number of moves needed for the two trains to pass each other?
If you wish you can check your solution
According to the English language wikipedia, there are about several categories of railway shunting puzzles. This post is about one of these categories, where a train or trains have to be maneuvered around a given track with some limitations.
The history of train shunting puzzles can’t go back further then that of railroads themselves, but a quick Google search did not reveal much.
British puzzle master Henry Dudeney also seems to have published several puzzles in this class, but his American counterpart Sam Loyd published two of them in his Encyclopedia of Puzzles. Besides these two, there is one classical which I’d like to present to you, if only because it’s the first one I ever encountered.
Let’s start with the two puzzles by Sam Loyd:
2) Primitive railroading
On page 89 of the cyclopedia of puzzles Sam Loyd poses the following problem:

Owing to the widespread interest taken in a simple railroad switch problem which I sprung on my friends some time ago, as well as in response to the request from many for another practical lesson in railroading, I present one which is an offshot from the first, and illustrates the difference between sidetracking a train or passing it through an y-branch., which reverses the direction of the trains.
In this specimen of primitive railroading we have an engine and four cars meeting an engine and three cars, and the problem, as in the previous one, is to ascertain the most expeditious way of passing the two trains by means of the switch or side track, which is only large enough to hold one engine or one car at a time.
No ropes, poles or flying switches are to be used, and it is understood that a car can not be connected to the front of an engine. It shows the primitive way of passing trains before the advent of modern methods, and the puzzle is to tell just how many times it is necessary to back or reverse the direction of the engines to accomplish the feat, each reversal of an engine being counted as a move in the solution.
This puzzle also appeared as nr 48 in Henry Dudeneys “Modern Puzzles”, and as nr 95 in Martin Gardners selection from Loyds Encyclopedia of Puzzles.
If you wish you can check the solution
3) The Switch Problem
Further down in his collection, on page 167, Sam Loyd presents a second problem. You may have noted that in the problem above Sam Loyd referred to a ‘first’ puzzle in this class, and I suppose that he had this puzzle in mind, even though this puzzle is listed after the first. The puzzle collection was probably first published in same daily or weekly newspaper column, and collected afterwards in his cyclopedia. According to Donald Knuth’s reference, the switch problem appeared in the Brooklyn Daily Eagle on 14 March 1897.

This is a practical problem for railroadmen, given to illustrate some of the complications of every-day affairs and is based upon the reminiscences of the days when railroading was in its infancy, before the introduction of double tracks, turn tables or automatic switches.
Yet, I am not going back to the days of our great-grandfathers, for there are those among us who are familiar with the advent of the iron horse, and the good lady who furnished me with the subject matter of the puzzle based it upon personal experience of what she called “the other day”. To tell the story in her own way, she said:
“We had just arrived at the switch station, where the trains always pass, when we found that the Limited Express had broken own. I think the conductor man said the smokestack had got hot and collapsed, so there was no draught to pull it off the track.”
The picture shows the Limited Express, with its collapsed engine, and the approach of the accommodation train from Wayback, which, by some means or other, must pass the stalled train.
The problem being to make the two trains pass, it is understood, that no ropes, poles, flying switches, etc. are to be employed; it is a switch puzzle pure and simple, the object being to get the accommodation train past the wreck and leave the latter train and each of its cars in the position as shown in the sketch.
It is necessary to say that upon the side switch there is but room enough for one car or engine, which is also true of the sections of the switch A, B, C and D.
The problem is tom tell just how many times the engineer must reverse; that is, change the direction of his engine to perform the feat. Of course the broken down engine can not be used as a motor, but must be pushed or pulled along just as if it were a car. The cars may be drawn singly or coupled together in any required numbers.
The problem complies with ordinary rules of practice and it is given to test your ingenuity and cleverness in discovering the quickest possible way to pass the broken down train.
This problem appeared as Puzzle no 30 in Tit Bits, and on March 14, 1897 in the Brooklyn Daily Express.
If you wish you can check the solution
4) Dudeney’s puzzle of passing two trains
How are the two trains in our illustration to pass one another, and proceed with their engines in front? The small sidetrack is only large enough to hold one engine or one car at a time, and no tricks such as ropes or flying switches, are allowed. Every reversal – that is, change of direction – of one of the engines is counted as a move in the solution. What is the smallest number of moves necesary?

To work on the problem, make a sketch of the track, and on it place a nickel and three pennies (heads up) for the engine and cars at the left, and a nickel and two pennies (tails up) for the engine and two cars on the right.
As you can see, this puzzle is identical to one of Sam Loyds puzzles above, so I’m not gonna publish the solution again. This version comes from Dudeney’s collection: 536 puzzles and curious problems, a collection published after Dudeneys death. In this book, it was puzzle 374.
5) Dudeney’s chifu chemulpo puzzle
Here is a puzzle that was once on sale in the London shops. It represents a military train—an engine and eight cars. The[Pg 135] puzzle is to reverse the cars, so that they shall be in the order 8, 7, 6, 5, 4, 3, 2, 1, instead of 1, 2, 3, 4, 5, 6, 7, 8, with the engine left, as at first, on the side track. Do this in the fewest possible moves. Every time the engine or a car is moved from the main to the side track, or vice versa, it counts a move for each car or engine passed over one of the points. Moves along the main track are not counted. With 8 at the extremity, as shown, there is just room to pass 7 on to the side track, run 8 up to 6, and bring down 7 again; or you can put as many as five cars, or four and the engine, on the siding at the same time. The cars move without the aid of the engine. The purchaser is invited to “try to do it in 20 moves.” How many do you require?

If you wish you can check the solution
6) Dudeney published a third puzzle, Mudville railway muddle, with two trains (engine + 40 cars each), which have to pass each other, but I have not been able to locate this puzzle. Professors Knuth short summary suggests to me that it is a simplified version of the puzzle at the top of this blog.
7)Anonymous classic

Move the engine so that the two wagons are interchanged and the engine is in the same spot again. The wagons can not pass through the tunnel, but the engine can. The engine can both push and pull with its front and rear, and even do both at the same time when that comes in handy. What is the minimum number of stops or reversals of direction of the engine that is needed?
If you wish you can check the solution
8)Anonymous classic variation

This puzzle is identical with the previous one, but the extra track allows for a faster solution. It can be found freely in many books and magazines.
(Thanks go to my daughter Margreet for the last two illustrations!)
If you wish you can check the solution
The puzzle at the start of this post was designed by me some 20 years ago. No doubt it was based on one of the many adaptions of puzzle 5. I recently rediscovered a page with notes om railway shunting puzzles, and one of them was this puzzle which I didn’t publish before.
I also would like to thank Professor Don Knuth for his laborious work in compiling indices on the works of Dudeney en Loyd. Most of the historical notes in this post are based on his indices.
9) Online puzzles: at armorgames
There are a couple of sites where you can play online:
http://armorgames.com/play/7324/railroad-shunting-puzzle
10) Other sites
http://www.freetraingames.org/game/36/Epic-Rail.html
http://www.wymann.info/ShuntingPuzzles/ (My friend Marco Roepers kindly pointed out this site, thanks, Marco!)
Most of you will know puzzles with two drawings or photos, with 5 to 10 tiny differences. Most of the serious puzzlers do not regard them as a serious challenge for their intellect. Anyway, they do require you to use your brain.
As an easy one, or not so easy one after the first difference, here is one i found through the facebook page of my friend Rahul Nadkarni:
Rahul mentions one Mark Townsend as the origin, but I’m not sure which one – there seem to be several around. And no, I’m not giving the solution. You are smart enough to find it yourself.
1) Squares

Which code belongs at the question mark?
If you wish, you can peek at a hint
Old visitors of this blog may note a change. The previous posts appeared about once a month, a pretty long period. They also offered a historical background of a type of puzzle. This post contains just 1 puzzle. I hope to do more of this 1 puzzle posts – they are easier to digest for the casual reader, they are lighthearted, and offer diversion.
The elaborate posts providing an overview of a type of puzzle require me a lot of time; time i don’t always have: there’s not only the time to write up a puzzle and check the solution, there’s also the need to do a lot of research. At the moment I have an issue about train shunting puzzles in the final stages, and also one about the Japanese Tangram, though I still have to do all the editing on this last one. And I have ideas for several more, such as the “zebra puzzles” and truth / false puzzles associated with Boolean logic. i still regard these posts as a main content provider for this blog.
I.m.h.o. they offer a lot of material. They also provide something in mental exercise which single puzzles do not offer.
Usually our brains are not really at work. Well, of course they do work, even tapping with a finger requires a lot of cells in our brain to work. What I mean is that our brain cells do a lot of routine work. We use our memory, and act from routine. This also applies to “brain workers”, such as accountants, programmers and managers. We humans have a natural tendency to fall back in routine. Single puzzles, especially when they are of a new type, force our brains to find new ways. We often don’t have a method at hand to solve them. This makes puzzles of a new type especially hard nuts to crack. In real life, an accountant may face this challenge when for example faced with a tooling called XBRL. A programmer may face such a challenge when trying to make the step from COBOL programming to C++ on smart phones.
After solving a single new puzzle, we have found some new ways to solve a problem. But often we do not yet have a clear distinction between the puzzle and the way we solved it. A series of puzzles of the same type helps our brains to add new heuristics to our problem solving skills, in the sense that our brains add a new routine to its arsenal of heuristics. I’m not sure how this relates to
1) Letters
A H I M N O V W X
Which letter is the odd one in this series? solution
2) Digits
0 3 6 7 8 9
Which digit does not belong in this series? solution
3) Numbers
3 4 7 13 20 33 53 86 139
Which number does not belong in this series? solution
4) Ells

Which L does not belong in this series? (solution)
5) Series
Which of the 4 series above is different from the rest? (solution)
Here are some new puzzles:
1) Old jacks
(1) Leather jacks always become very old
(2) Old jacks turn brown
Which conclusion is valid?
a) All brown jacks are old
b) No old jack is blue
c) Some leather jacks are brown
d) None of the above
You can check your answer at solution 85
2) Dirty Pigs
(1) No dirty pig is fat;
(2) No meager pig is pink;
Which conclusion is valid?
a) All fat pigs are clean;
b) All dirty pigs are meager;
c) All pink pigs are fat;
d) All pink pigs are clean;
e) All of the above;
You can check your answer at solution 96
3) New coats
(1) No new coat of mine is not made of plastic;
(2) All plastic coats are closed with zips;
Which conclusions are valid?
a) All plastic coats are mine;
b) All zipped coats are mine;
c) All coats closed with zips are old;
d) All my new coats are closed with zips;
You can check your answer at solution 75
These puzzles are based on a mathematical concept called Sets, but you can solve them without this knowledge. Sets are now taught at all high schools in the Netherlands, and I suppose also in other countries. Some Googling on Venn diagrams and puzzles revealed little or no sites. This surprises me as it usually regarded as a good educational practice if students are also taught to apply their knowledge to practical problems, although this may depend on the preferred learning style of the student.
Puzzles of this type do have a history. One not so well know puzzle master from Victorian England is Charles Lutwidge Dodgson (1832 – 1898), better known as Lewis Carroll, author of children tales as Alice in Wonderland and Through the looking glass.
In his daily life he taught mathematics, and the story goes that Queen Victoria loved Alice in Wonderland so much that she wrote the author and asked for a copy of his next book. Charles felt honoured, and duly send her a copy of his next book – a treatise on a mathematical subject.
Charles was also an avid puzzle designer. In his books “Symbolic logic” and “The game of Logic”, later republished by Dover press, he devised an elaborate mechanism to solve set problems like those above. Modern mathematicians would use Venn diagrams to solve the same class of problems. Puzzles like these are somtimes called Soriteses.
Here are some examples of the type of puzzles you can find in his book:
4) Wasps
(1) All wasps are unfriendly
(2) All unfriendly creatures are unwelcome
What conclusion can be found?
The puzzles can be made slightly more complex by adding mote statements, by more types of objects that play a role, or by adding negatives. Here are some of his puzzles that comprise 3 statements:
5) Sane
(1) Everyone who is sane can do Logic
(2) No lunatics are fit to serve on a jury
(3) None of your sons can do Logic
What conclusion can be found?
6) Flowers
(1) Coloured flowers are always scented
(2) I dislike flowers that are not grown in the open air
(3) No flowers grown in the open air are colourless.
What conclusion can be found?
7) Showy talkers
(1) Showy talkers think too much of themselves;
(2) No really well informed people are bad company;
(3) People who think too much of themselves are not good company.
What conclusion can be found?
Lewis Carroll was thinking in terms of modern day sets, and made no secret of it. At the end of each puzzle, he added a note about what the Universe of discourse in that puzzle was, wand what sets needed to be considered. For example, in puzzle 4 this was:
Universe = persons; a=good company; b=really well-informed; c=show talkers; d=thinking too much of ones self;
It is of course possible to create puzzles in this vein with more statements. Here is one from Charles L. Dodgsons book with four statements:
8) Birds in the aviary
(1) No birds, except ostriches, are 9 feet high;
(2) There are no birds in this aviary that belong to any one but me;
(3) No ostrich lives on mince pies;
(4) I have no birds less than 9 feet high;
What conclusion can be found?
Dodgson constructed puzzles much more complex; his longest is made up of 10 statements:
9) Animals in the house
(1) The only animals in this house are cats;
(2) Every animal is suitable for a cat, that loves to gaze at the moon;
(3) When I detest an animal, I avoid it;
(4) No animals are carnivorous, unless they prowl at night;
(5) No cat fails to kill mice;
(6) No animals ever take to me, except what are in this house;
(7) Kangaroos are not suitable for pets;
(8) None but carnivora kill mice;
(9) I detest animals that do not take to me;
10) Animals, that prowl at night, always love to gaze at the moon.
What conclusion can be found?
The illustration below comes from Gbrainy, a puzzle program distributed with Ubuntu linux.
My wife and I first discovered it on one of our holidays, when our son Piet-Jan had equipped an old laptop with Ubuntu linux. GBrainy gave us several evenings with much needed mental exercise. It features logic, calculation, memory and verbal puzzles and exercises. One of the puzzles was this one:

I must admit it took me some time to figure it out, and you can check the solution.
Some logicians and mathematicians maintain that there are two ways of thinking: deductive and inductive. Deductive reasoning is the type of reasoning where you have all elements available, and your deductions involve logical reasoning, but the reasoning does not include anything new. One might say that your reasoning takes your from general to specific. An easy example: All cows are animals. Bella is a cow. Conclusion: Bella is an animal. Inductive reasoning goes the other way around: from special to general. In the puzzle above this type of reasoning is very clear: you start looking for what the commons properties in the figure are, and what letters can be associated with them. Finding the properties is the inductive part: you don’t know what the common properties are, and you have to discover them.
The puzzle made me thinking, and I designed several others, some of which I took the liberty to present them to the GBrainy group, others are presented here for the first time. Several of my fellow workers, such as Jan Zoomers, Jon Koeter, Michiel Matthijssen and Pieter Vuijk tested some of them, for which I am grateful to them.

(Give up? Don’t check the solution to soon).

(Give up? Don’t check the solution too soon).
In a previous post I mentioned inductive and deductive reasoning. One might say that in inductive reasoning all elements are known, while deductive logic tries to find the general underlying a pattern.
Famous game inventor Robert Abott designed a game “Eleusis” which is based on inductive reasoning, and though this is a blog on puzzles I hope to spend a future article on this game – there are sufficient similarities.
Another area where inductive reasoning is used, is in many IQ tests. Many of them have exercises consisting of a series of numbers, where the person taking the test is asked to find the next number. Patterns are usually purely based on elementary arithmetic.
Here are some exercises, ranging from elementary to difficult:
1) 3, 6, 9, …
2) 2, 6, 10, 14, …
3) 3, 12, 48, …
4) 19, 15, 11, …
5) 128, 64, 32, …
The sequences above are very simple, one operation is repeated again and again.
Things can however be made slightly more complicated, and this is the level you will find in many IQ tests.
6) 3, 6, 4, 8, 6, 12, 10, … (solution 41)
7) 3, 5, 8, 10, 13, 15, 18, .. (solution 51)
8 ) 3, 8, 3, 11, 3, 14, 3, .. (solution 7)
9) 100, 90, 180, 170, 340, 330, .. (solution 14)
10) 260, 130, 120, 60, 50, … (solution 20)
11) 15, 7, 22, 14, 29, 28, … (solution 28)
12) 18, 36, 13, 18, 8, 9, … (solution 35)
The nice thing about this type of puzzles is that after doing a series, you know the patterns to look for, which makes the next one easier to solve. As a result, you actually score higher when you consecutively take an IQ test where they have this kind of exercises. So yes, solving these puzzles actually makes you score higher at IQ tests.
13) 5, 11, 23, 47, … (solution 58)
14) 38, 22, 14, 10, … (solution 64)
15) 4, 12, 26, 54, … (solution 72)
16) 248, 86, 32, 14, … (solution 79)
17) 3, 4, 7, 11, … (solution 84)
18) 3, 6, 11, 18, … (solution 94)
19) 3, 7, 12, 18, 25, … (solution 104)
20) 3, 5, 9, 15, 25, … (solution 114)
21) 2, 5, 10, 17, 26, … (solution 124)
22) 3, 10, 29, … (solution 133)
23) 4, 8, 24, 96, 480, … (solution 142)
Occasionally, you will encounter sequences which will be posed in a different form, such as:
24) 5, 9, …, 17, …, …, 29. (solution 149)
25) One form occasionally used in puzzle books and magazines is the rectangle or square:
| 7 | 12 | 5 |
| 17 | 16 | 18 |
| 9 | 3 | .. |
26) Puzzle magazines often love to add illustrations. That is nothing new, Sam Loyd in the 19th century added an illustration to almost any puzzle in his Encyclopedia of Puzzles. Here is an example as they might appear in puzzle magazines.
In the supermarket, you find several fruit bags with labels. Unfortunately, one of the labels is damaged. Can you figure out what the price on the damaged label is?

Should the puzzle beat you, you can look up the solution 37
Things can be taken too far. For example, take the next sequence:
1, 2, 4, 8, 16, 31, ….
No, the 31 is correct, it is not a typo for 32, it is really 31.
You may spend days thinking about this sequences and never find an answer. Unless you happen to have stumbled on the problem before, you are not likely to stumble on the solution, which is 57.
The logic behind this series is that it is the number of regions formed by joining points on a circle:
Further reading:
http://www.nextnumber.com
http://www.nextnumber.com/show?39
The puzzles in this post are extracted from the previous river crossing post, as that post grew too large. There is a common characteristic too these puzzles, though I find it hard to give an exact definition of this common property.
1) Bigamists
Back to the form of the puzzle with Jealous couples. M.G. Tarry has complicated the problem by assuming that the wives are unable to row. He also proposed a further complication by suggesting that one of the husbands is a bigamist traveling with both his wives.
Steven Kransz’s in his book: “Tecbniques of problem solving” gives a similar variation: “A group consists of two men, each with two wives, who want to cross a river in a boat that only holds two people. The jealous bigamists agree that no woman should be located either in the boat or on the river banks unless in the company of her husband.” That is how Miodrag Petković cites it in his book: Famous puzzles of great mathematicians. The latter condition makes it impossible to solve, and I guess that the latter condition should actually read “The jealous bigamists agree that no woman should be located either in the boat or on the river banks with the other man unless in the company of her husband.”
For the solution, see solution 121
2) A family affair
A recent addition tot his class of puzzles, which surfaced on the web as a flash game, is the following: A father and two sons, a mother with two daughters, and a thief guarded by a policeman want to cross a river. Their only means of transport is a raft able to carry 2 people. There are some problems:
• The Father is a rather nasty guy who will beat up the two girls if the mother is not present
• I regret to say that the Mother is equally nasty and will beat up the two boys unless the father is present
• The thief will beat up the boys, girls and adults if not accompanied by the police.
• Only the Father, the Mother and the Policeman know how to operate the raft
How many trips do you need to get them all across?
The site is in an Asian language, which suggests that the puzzle is of Chinese/Japanese or Korean origin. I welcome any information on the inventor of this puzzle. You can find it here.
You can find the solution at number 131
Actually this puzzle has a strong connection to both the elementary farmer-wolf-goat-cabbage puzzle and the bigamists puzzle.
3) The farmer, the kids and the pets.
Another recent flash based river crossing panel can be found at http://www.smart-kit.com/s888/river-crossing-puzzle-hard/>this site
The rules are simple:
A farmer, his son and daughter, and their pets need to cross a river. The pets are an aggressive dog, 2 hamsters, 2 rabbits. There is a small two-seater boat they can use. All 3 people know how to use the boat, but none of the animals can.
The solution is number 151
4 ) The two polygamists
Here is a new puzzle, which occurred to me while traveling by car today: Two polygamists, each accompanied by three wives, want to cross a river with a boat that can hold only 2 people at a time. The two men are so jealous, that they wont allow any of their wives to be in the boat, or on one of the riverbanks, with the other man unless he himself is present. An extra complication is that only one of the men, and one of his wives, can row.
How many crossings do they need?
You can find the solution at number 135
This time we make a side step from the previous series of river crossing puzzles. Where you had only a boat ion the previous series of puzzles, this time the only allowed way is to walk over bridges.
The bridges of Konigsberg is a classical mathematical problem solved by mathematician Leonard Euler.
The town of Konigsberg is situated along a river, with two islands in the middle, connected by 7 bridges. On Sunday afternoons, the inhabitants tried to make a walk in such a way that they crossed every bridge exactly once. No swimming or boats were allowed.

Euler proved that this was impossible, and his prove provided the base for what is now known as graph theory. His concept is simple to understand. He reduced the riverbanks and islands to dots, and the bridges to lines. It will be clear that if an intermediate dot has an uneven number of lines, this knot will have a problem: the walker should exit the dot as often as he enters it. Only at the start and at the end of the walk there can be a dot with an uneven number of lines.
The question of course arises: If it is impossible, and if the mathematics is clear, how can we still use it for puzzles?
Over the past two centuries a few puzzles have been invented. Here they are:
1) The monk

British puzzlemaster Dudeney reduced the problem to one island and five bridges. In this situation the bridges can all be crossed exactly once.
His problem is: If a monk want to start somewhere, in how many ways can he cross all bridges exactly once?
You can check your solution.
2) The two contractors
2a) The contractor on the northern shore.
The town had two important and rich contractors. One lived on the northern river bank, the other on the southern riverbank. The favorite Kneipe, or pub, of both was on the rightmost island with 5 bridges.
Hearing of Eulers method, the contractor on the northern riverbank decided to build an extra bridge at his own cost, which would allow him to start at his home, cross all bridges once, and end for a pint in his favorite pub.
Where did he build this bridge?
You can check your solution.
2b) The contractor on the southern shore.
When the contractor on the southern shore saw the new bridge, he realized that it was impossible for him to make a sunday afternoon trip and end in the same pub. He immediately decide to build an extra bridge at his own cost in such a way that he himself was able to start from his own home, cross all bridges exactly once, and end up in their favorite pub.
Where did he build this bridge?
You can check your solution.
2c) The mayor.
The mayor, seeing the two new bridges, called the two assembly together and decided to build a third new bridge, in such a way that all inhabitants of the town, no matter where they lived, could start from home, cross all bridges exactly once, and end up in the pub on the rightmost island.
Where did he build this bridge?
You can check your solution.
3) The pastor en the penitence
Here is a new puzzle for you:
A mayor with a good sense of history restored the bridges to the original situation at the time of Euler.
However, during one of the many wars in the region, one of the bridges was destroyed and rebuild at another spot. The new situation did allow the citizens to cross all bridges exactly once on their Sunday afternoon walks, provided they lived on either the northern or southern riverbank. See the following illustration:

When one of his parochians confessed him the rather severe sin of eating 7 cakes on a single afternoon, the pastor – for this sin of gluttony – ordered him to make the Sunday afternoon from his home walks in all possible ways.
Starting on the southern riverbank, how many ways are there to cross all bridges exactly once?
You can check your solution.