Hearts and Spades in a Row

From a deck of playing cards remove hearts ace to seven, and spades ace to seven. Now place them on a table in a row so that the number of cards between the two aces is 1, the number of cards between the two twos is 2, and so on up to the number of cards between the two sevens, which should be 7.

Do so in such a way that the six cards between the two sixes are all the same suit.

A brute force solution: We start with the two sixes with six empty places in between. We must fill those six places with exactly one of each number 1 to 5, as well as 7, while following the rules of spacing.

To follow the rules of spacing, the 1 must be adjacent to one of the sixes, and the 2 must be on the other side. Ignoring reverse order solutions, the only two openings are:

 1 6 1 * * * 2 * 6 2
1 6 1 * * * * 2 6 _ 2

Now, filling in the 3:

   3 1 6 1 3 * * 2 * 6 2
1 6 1 * * * 2 3 6 2 _ 3

3 1 6 1 3 * * * 2 6 _ 2
1 6 1 * * 3 * 2 6 3 2

The 4:

       3 1 6 1 3 * 4 2 * 6 2 4
3 1 6 1 3 * * 2 4 6 2 _ _ 4
1 6 1 * * 4 2 3 6 2 4 3
4 1 6 1 * 4 * 2 3 6 2 _ 3
4 _ 1 6 1 4 * * 2 3 6 2 _ 3

3 1 6 1 3 4 * * 2 6 4 2
3 1 6 1 3 * * 4 2 6 _ 2 4
4 _ 1 6 1 4 * 3 * 2 6 3 2
4 1 6 1 * 4 3 * 2 6 3 2
1 6 1 * * 3 4 2 6 3 2 4

When placing the 5, we can easily reject any solution that would leave more than 1 empty place in each suit, since we only have the 7 left:

      5 3 1 6 1 3 5 4 2 * 6 2 4
3 1 6 1 3 * 5 2 4 6 2 _ 5 4
5 _ 1 6 1 * 5 4 2 3 6 2 4 3
4 _ 1 6 1 4 5 * 2 3 6 2 5 3
4 5 1 6 1 4 * 5 2 3 6 2 _ 3

3 1 6 1 3 4 5 * 2 6 4 2 5
3 1 6 1 3 4 * 5 2 6 4 2 _ 5
5 3 1 6 1 3 5 * 4 2 6 _ 2 4
5 _ 4 1 6 1 5 4 3 * 2 6 3 2
4 1 6 1 * 4 3 5 2 6 3 2 _ 5
5 _ 1 6 1 * 5 3 4 2 6 3 2 4

And finally we place the 7 such that no empty places are left, leaving only the valid solutions:

       7 3 1 6 1 3 4 5 7 2 6 4 2 5
5 7 4 1 6 1 5 4 3 7 2 6 3 2
4 1 6 1 7 4 3 5 2 6 3 2 7 5

The reverse order of each valid solution is also valid, so there are 6 valid sequences of numbers (ignoring the suits). Obviously the choice of "inside" suit is also arbitrary, as is the order of the two sixes (of different suits), so with actual cards (considering the suits) there are more valid arrangements, but the solutions are fundamentally the same.

• Nicely done! I was going to do this too, but didn't have time today to make the necessary edits to my answer. +1 Nov 20, 2019 at 15:47
• @Randal'Thor Curiously all of the valid solutions have the inside 2 placed adjacent to the 6, just like you did. Lucky guess? =) Nov 20, 2019 at 16:10
• Lucky, or based on mathematical intuition. It feels like there should be a simple algorithm: place the 1 on the end, the 2 on the other end, the 3 next to the 1, the 4 next to the 2, ... It's not quite that simple, but trying at least some steps seems natural. The more interesting thing is that the inner 4 is in the same position in all the valid solutions - although that really does feel like just coincidence. Nov 20, 2019 at 16:15
• @Randal'Thor, if you think there is a simple rule, can you help completing this answer? Dec 3, 2019 at 9:41

This works, although I'm not sure if it's unique:

7 3 1 6 1 3 4 5 7 2 6 4 2 5

Everything between the two sixes is hearts, and everything outside of them is spades.

How I found it

We have two 6s (red and black) with six cards between them that must be all the same colour (let's say red). Key fact:

That accounts for ALL the hearts: 1, 2, 3, 4, 5, 7 between plus one of the 6s. So we've got ALL the spades outside.

Now, to begin with,

the 1s have only one card between them, but one of them is inside the 6s and the other outside. So we have

1 6 1 * * * * * 6

After that,

the red 2 must be in one of the two rightmost "inside" positions. I made a guess and put it on the right-hand end:

1 6 1 * * * * 2 6 * 2

On another hunch, I decided to put 3 with 1 and 4 with 2, hoping for an odds & evens pattern:

3 1 6 1 3 4 * * 2 6 4 2

Also,

the black 7 can't be too far out because we only have so many cards still available to fill the gaps. There's really only one way to do it now: 7 3 1 6 1 3 4 5 7 2 6 4 2 5