Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A standard domino set has 28 unique pieces:

enter image description here

Given a list of 28 or fewer unique dominoes, output the list required to make a complete set.

Input and output dominoes are specified by two digits - the number of pips on each side of the domino, e.g. 00, 34, 40, 66.

The digits may be given in any order, so 34 is the same domino as 43

Example Inputs

00 01 02 03 04 05 06 11 12 13 14 15 16 22 23 24 25 26 33 34 35 36 44 45 46 55 56 66
00 10 11 20 21 22 30 31 32 33 40 41 42 43 44 50 51 52 53 54 55 60 61 62 63 64 65 66
00 01 02 03 04 05 06 11 12 13 14 15 16 22 23 24 25 26 34 35 36 44 45 46 55 56 66
00 02 03 04 05 06 11 13 14 15 16 22 24 25 26 33 35 36 44 46 55 66
<empty list>

Corresponding Example Outputs

<empty list>
<empty list>
33
01 12 23 34 45 56
00 01 02 03 04 05 06 11 12 13 14 15 16 22 23 24 25 26 33 34 35 36 44 45 46 55 56 66
share|improve this question
2  
What input formats are allowed? Lists of strings? Lists of lists of integers? – Martin Ender Feb 28 at 9:33
    
@Martin I was assuming we have a meta consensus somewhere along the lines of "whatever list, array, set, collection, vector, matrix,... Is appropriate for your language. Members may be numbers or strings" – Digital Trauma Feb 28 at 16:53

CJam, 11 bytes

{:$7Ym*:$^}

An unnamed block (function) with I/O as a list of pairs of integers.

Test it here.

Explanation

:$   e# Sort each pair in the input.
7Ym* e# Get all pairs with elements in range [0 .. 6] using a Cartesian product.
:$   e# Sort each pair.
^    e# Symmetric set-difference. This will remove all pairs that are in the input
     e# and also remove duplicates, because it's a set operation.
share|improve this answer

Pyth, 12 10 bytes

-.CU7 2SMQ

Input and output in format [[0, 0], [0, 1], ...].

   U7       generate range [0, 1, ..., 6]
 .C   2     all combinations-with-replacement of 2, generates [[0,0],[0,1],...]
         Q  get the input
       SM   sort each domino (turns ex. [1,0] into [0,1])
-           remove the map-sort'd input from the full array

Try it here.

Thanks to @MartinBüttner for saving 2 bytes with a different input/output format!

share|improve this answer

JavaScript (ES7 proposed), 80 76 bytes

s=>[for(n of d="0123456")for(o of d.slice(n))if(s.search(n+o+'|'+o+n)<0)n+o]

Takes input as a space-separated string and returns an array of strings. Array comprehensions really pull their weight for this one.

share|improve this answer

Ruby 74 bytes

->b{a=(0..27).map{|i|"%d%d"%[i%7,(i+i/7)%7]}
b.map{|e|a-=[e,e.reverse]}
a}

Takes an array of strings, returns an array of strings.

Commented in test program

f=->b{a=(0..27).map{|i|"%d%d"%[i%7,(i+i/7)%7]} #generate complete set of dominos (each domino once) and store in a
b.map{|e|a-=[e,e.reverse]}                     #remove provided dominos (check both forward and reverse representations)
a}                                             #return a

p f[%w{00 01 02 03 04 05 06 11 12 13 14 15 16 22 23 24 25 26 33 34 35 36 44 45 46 55 56 66}]
p f[%w{00 10 11 20 21 22 30 31 32 33 40 41 42 43 44 50 51 52 53 54 55 60 61 62 63 64 65 66}]
p f[%w{00 01 02 03 04 05 06 11 12 13 14 15 16 22 23 24 25 26 34 35 36 44 45 46 55 56 66}]
p f[%w{00 02 03 04 05 06 11 13 14 15 16 22 24 25 26 33 35 36 44 46 55 66}]
p f[[]]

Output

[]
[]
["33"]
["01", "12", "23", "34", "45", "56"]
["00", "11", "22", "33", "44", "55", "66", "01", "12", "23", "34", "45", "56", "60", "02", "13", "24", "35", "46", "50", "61", "03", "14", "25","36", "40", "51", "62"]

In the last example (input empty list) note the order of generation of the complete list of dominoes using modular arithmetic. 7 Doubles are generated first, then 7 dominoes with a difference of 1 (or 6) pips between each side, then 7 dominoes with a difference of 2 (or 5) pips, and finally 7 dominoes with a difference of 3 (or 4) pips.

share|improve this answer

Mathematica, 49 bytes

Complement[Join@@Table[{x,y},{x,0,6},{y,0,6}],#]&

Input is list of list of integers.

share|improve this answer
    
Fails on the last test case; remember, these are unordered sets. – LegionMammal978 Feb 29 at 11:15

Haskell, 65 bytes

f x=[[a,b]|a<-"0123456",b<-[a..'6'],notElem[a,b]x&&notElem[b,a]x]

Usage example:

*Main> f ["00","02","03","04","05","06","11","13","14","15","16","22","24","25","26","33","35","36","44","46","55","66"]
["01","12","23","34","45","56"]

Iterate a in an outer loop over all digits from 0 to 6 and b in an inner loop over all digits from a to 6 and keep those ab where neither ab nor ba are found in the input string.

share|improve this answer

Perl, 48 + 1 = 49 bytes

for$=(0..6){for$.($=..6){/$=$.|$.$=/||say$=.$.}}

Requires the -n flag, and the free -M5.010|-E:

$ perl -nE'for$=(0..6){for$.($=..6){/$=$.|$.$=/||say$=.$.}}' <<< '00 02 03 04 05 06 11 13 14 15 16 22 24 25 26 33 35 36 44 46 55 66'                      
01
12
23
34
45
56

Pretty boring answer overall, but here goes with an ungolfed version:

# '-n' auto reads first line into `$_`:
# $_ = <>;
foreach $a (0..6) {
  foreach $b ($a..6) {
    say $a . $b unless $_ =~ /$a$b|$b$a/;
  }
}
share|improve this answer

Seriously, 16 bytes

,`S`M7r;∙`εjS`M-

Takes input as a list of strings, outputs a list of strings

Try it online!

Explanation:

,`S`M7r;∙`εjS`M-
,`S`M             map: sort each input string
     7r;∙         cartesian product of range(0,7) ([0,1,2,3,4,5,6]) with itself
         `εjS`M   map: join on empty string, sort (results in all valid dominoes with some duplicates)
               -  set difference (all values present in valid dominoes set not present in input, with duplicates removed)

Actually, 13 bytes (non-competing)

♂S7r;∙`εjS`M-

This is identical to the Seriously answer (with the exception of implicit input and ♂S being a shorter way to short each input string).

Try it online!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.