473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sorting dominoes

Essentially, I'm trying to sort 12 dominoes. Each domino has two different
numbers and there are two of every number. Identical dominoes are possible,
but doubles are not.

The problem is to place the dominoes in a line, side to side, so that two
columns (or rows, depending how you orientate them) are formed, with each
number appearing once in each column(row).

I thought this would be the easy part of the program I'm writing, but so far
some initial states have defeated every attempt I've made, short of
re-shuffling the dominoes after an arbitrary number of attempts.

I'm sure I'll work out an effective algorithm eventually, but I suspect I'm
re-inventing the wheel, so any hints on the best way to tackle this would be
appreciated!

DaveM
Nov 22 '05 #1
2 2345
So if you have the dominoes (1 2), (3 2) and (3 1) you must arrange them as
1|2|3
2|3|1
? If so, then it seems to me your algorithm is this:
1. pick an arbitrary domino to be first, and an arbitrary side to be the "top"
2a. until the dominoes are exhausted, pick the other domino with the same digit
as the "bottom" of the last domino picked, and put that digit on the top.
2b. If there is no domino with the same digit, then pick an arbitrary domino as
in step 1

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDd/5hJd01MZaTXX0RAvo0AJ4kBmMDXP8hDDwmguu9aL6vvMpIUgCf eLCr
aZrw1D45Z1seuXR+ojdSmKg=
=+FyN
-----END PGP SIGNATURE-----

Nov 22 '05 #2
DaveM wrote:
Essentially, I'm trying to sort 12 dominoes. Each domino has two different
numbers and there are two of every number. Identical dominoes are possible,
but doubles are not.

The problem is to place the dominoes in a line, side to side, so that two
columns (or rows, depending how you orientate them) are formed, with each
number appearing once in each column(row).

I thought this would be the easy part of the program I'm writing, but so far
some initial states have defeated every attempt I've made, short of
re-shuffling the dominoes after an arbitrary number of attempts.

I'm sure I'll work out an effective algorithm eventually, but I suspect I'm
re-inventing the wheel, so any hints on the best way to tackle this would be
appreciated!

DaveM


Assuming your dominoes are expressed as a list of tuples, e.g. [ (1, 2),
(3, 2), (3, 1) ].

The pseudo-code would probably be as follows:

1) create a corresponding list of dominoes with each domino reversed
2) concatenate your original list of dominoes with the list of flipped
dominoes
3) sort the new concatenated list
4) take every other element in the sorted list, e.g. using [::2]

I hadn't actually thought about it enough to verify if it works all the
time.
Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.