# Which dominoes are missing?

A standard domino set has 28 unique pieces:

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

• What input formats are allowed? Lists of strings? Lists of lists of integers? Feb 28 '16 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" Feb 28 '16 at 16:53
• Does that mean that we can request each domino as a pair of integers, for example 03 16 = [0, 3], [1, 6]? Dec 29 '17 at 11:49
• @FlipTack Yes, of course Jan 1 '18 at 0:24

## 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.

• Why do you need the {} brackets? Jun 14 '18 at 1:49

## 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!

## 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.

# 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.

# Julia 0.6, 47 bytes

A->setdiff([[i,j]for i=0:6 for j=i:6],sort.(A))


Try it online!

(Corrected range start thanks to JayCe.)

## 48 bytes

A->[(i,j)for i=0:6 for j=i:6 if[i,j]∉sort.(A)]


Try it online!

• I think the zero dominoes seem to be missing from your 3rd TIO test case. For i=0:6 maybe ? Jun 17 '18 at 2:17
• That's what I get from trying to post half asleep at 3AM! Yep, fixed now (hopefully), thanks. Jun 17 '18 at 7:41

# 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/;
}
}


# Python 2, 91 bytes

lambda A,S="0123456":sum([[i+j for j in S[int(i):]if(i+j in A)+(j+i in A)<1]for i in S],[])


Try it online!

# JavaScript (SpiderMonkey), 69 bytes

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


Try it online!

optimized from Neil's

# R, 111 bytes

function(s,p=paste0,L=lapply)setdiff(p(sequence(1:7)-1,rep(0:6,t=1:7)),L(L(strsplit(s,''),sort),p,collapse=''))


Try it online!

Not really proud of this, but R is not very "golfy" in splitting/concatenating strings...

# 05AB1E, 12 11 bytes

6Ýã€{JI€{KÙ


-1 byte thanks to @Emigna.

Try it online.

Explanation:

6Ý         # [0,1,2,3,4,5,6]
ã        # Duplicate and take the cartesian product (pair up each)
€{      # Sort each pair
J     # Join them together to strings
I€{        # Sort each pair-string of the input
K          # Remove all pairs from the input from the cartesian list
Ù          # Only leave unique values


# Mathematica, 49 bytes

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


Input is list of list of integers.

• Fails on the last test case; remember, these are unordered sets. Feb 29 '16 at 11:15
• I would agree with @LegionMammal978; this answer appears to be invalid. Aug 9 '18 at 22:15

# Java 8, 105 bytes

A void lambda accepting a mutable java.util.Set<String>.

s->{for(int i=0,a,b;i<49;)if(s.add(""+(a=i/7)+(b=i++%7))&(s.add(""+b+a)|a==b))System.out.print(" "+a+b);}


Try It Online

## Ungolfed

s -> {
for (int i = 0, a, b; i < 49;)
if (
s.add("" + (a = i / 7) + (b = i++ % 7))
& (
s.add("" + b + a)
| a == b
)
)
System.out.print(" " + a + b);
}


## Acknowledgments

• -1 byte thanks to Jonathan Frech
• int i=0,a,b;while(i<49 can be for(int i=0,a,b;i<49;. Jun 14 '18 at 11:42

# Jelly, 8 bytes

Ṣ€7ḶŒċ¤ḟ


Try it online!

Argument is a list of length-2 lists of integers. The footer transforms the input from the format in the test cases to the format this solution accepts.

# J, 26, 24 bytes

-2 bytes thanks to FrownyFrog

(;(,.i.,])&.>i.7)-.\:~"1

• (;(,.i.,])&.>i.7) calculates the full set (this part could be golfed further, I believe. And please do if you see how...)
• -. is "set minus"
• /:~"1 orders each of the inputs

Try it online!

## Original

Try it online!

((#~<:/"1)>,{;~i.7)-./:~"1

• (;(,.i.,])&.>i.7) saves 2 (reverses the order) Jun 14 '18 at 6:45
• @FrownyFrog thanks, updated. Jun 18 '18 at 20:51

# Python 2, 89 86 bytes

Saved a few bytes by simplifying domino set generation.

lambda z,s="0123456":{x+y for x in s for y in s[int(x):]}-{(a+b,b+a)[a>b]for a,b in z}


Try it online!

Takes a list of strings like ["00", "10", "02] as an argument for the dominoes. Returns python set objects, which are unordered distinct lists.

Explanation

# anonymous function, s should always have its default value
lambda z,s="0123456":
# contents are a set
{                                  }
# iterate over characters in string
for x in s
# for each x, iterate over x from index of current item forward
for y in s[int(x):]
# add characters together for domino string
x+y
# contents are a set, return the difference between these two sets
-{                          }
# iterate over items in input list, split strings into two characters
for a,b in z
# sort strings in input list (so that i.e. "10" => "01")
# essentially, "ab" if a<b, otherwise "ba"
(a+b,b+a)[a>b]


## 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.

## Seriously, 16 bytes

,SM7r;∙εjSM-


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

Try it online!

Explanation:

,SM7r;∙εjSM-
,SM             map: sort each input string
7r;∙         cartesian product of range(0,7) ([0,1,2,3,4,5,6]) with itself
εjSM   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;∙εjSM-


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!

• You have duplicates in the output Jun 13 '18 at 19:12
• @DigitalTrauma This is due to backwards-incompatible changes made since the time of posting.
– user45941
Jun 13 '18 at 22:49

# racket

(define (missing-dominoes input)
(filter
(lambda (n)
(not (member n (map
(lambda (n)
(let ((x (quotient n 10)) (y (remainder n 10)))
(if (<= x y) n (+ (* y 10) x))))
input))))
(for*/list ([i (in-range 7)] [j (in-range i 7)])
(+ (* 10 i) j))))

• Nice to see people golfing in racket! This is a code-golf question so you probably ought to include your bytecount in your answer. You could also definitely remove quite a bit of whitespace from this answer. Jun 18 '18 at 17:29
• I would agree with @WW in that this answer does not seem to be sufficiently golfed to be valid. Aug 9 '18 at 22:17