缺少哪些多米诺骨牌?


34

一个标准的骨牌组有28件独特:

在此处输入图片说明

给定28个或更少的唯一多米诺骨牌的列表,输出完整的列表所需的列表。

输入和输出的多米诺骨牌是由两个数字指定-点数对多米诺的每一侧上的数量,例如00344066

数字可以以任何顺序给出,因此3443

输入示例

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>

相应的示例输出

<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

2
允许哪些输入格式?字符串列表?整数列表列表?
Martin Ender

1
@马丁我是假设我们有沿的线条元共识的地方“无论列表,阵列,组,集合,向量,矩阵,...是适合您的语言成员可以是数字或字符串。”
数字创伤

这是否意味着我们可以将每个多米诺骨牌要求为一对整数,例如03 16= [0, 3], [1, 6]
FlipTack

1
@FlipTack是的,当然
Digital Trauma

Answers:


10

CJam,11个字节

{:$7Ym*:$^}

I / O作为整数对列表的未命名块(函数)。

在这里测试。

说明

:$   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.

为什么需要{}括号?
Chromium

6

Pyth,12个 10字节

-.CU7 2SMQ

输入和输出格式[[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

在这里尝试。

感谢@MartinBüttner以不同的输入/输出格式保存2个字节!


4

JavaScript(建议使用ES7),80 76字节

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

将输入作为空格分隔的字符串,并返回字符串数组。数组理解确实可以发挥其作用。


3

Ruby 74字节

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

接受一个字符串数组,返回一个字符串数组。

在测试程序中注释

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[[]]

输出量

[]
[]
["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"]

在最后一个示例(输入空列表)中,请注意使用模块化算术生成完整的多米诺骨牌列表的顺序。首先生成7个双打,然后生成7个多米诺骨牌,每侧之间的差为1(或6)个点,然后是7个多米诺骨牌,其差值为2(或5)个点,最后是7个多米诺骨牌,其差值为3(或4)。点。


3

朱莉娅0.6,47字节

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

在线尝试!

(由于有了JayCe,校正后的范围开始了。)


48字节

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

在线尝试!


我认为您的第三个TIO测试案例似乎缺少零个多米诺骨牌。因为我= 0:6也许?
JayCe

这就是我尝试在凌晨3点半睡着后得到的结果!是的,现在修复(希望如此),谢谢。
sundar-恢复莫妮卡

2

Perl,48 + 1 = 49字节

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

需要-n标志,而免费-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

总体来说,这个答案很无聊,但是这里有一个非高尔夫版本:

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



2

R,111字节

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=''))

在线尝试!

对此并不感到特别自豪,但是R在拆分/连接字符串方面不是很“古怪”。


2

05AB1E12 11 字节

6Ýã€{JI€{KÙ

-1个字节感谢@Emigna

在线尝试。

说明:

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

1

Mathematica,49个字节

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

输入是整数列表。


3
在最后一个测试用例上失败;请记住,这些是无序集合。
LegionMammal978 '16

我会同意@ LegionMammal978; 这个答案似乎无效。
乔纳森·弗雷希

1

Java 8,105字节

无效的lambda接受可变的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);}

在线试用

不打高尔夫球

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);
}

致谢

  • -1字节感谢乔纳森·弗雷希(Jonathan Frech)

1
int i=0,a,b;while(i<49可以for(int i=0,a,b;i<49;
乔纳森·弗雷希


1

J,26、24字节

-2字节归功于FrownyFrog

(;(,.i.,])&.>i.7)-.\:~"1
  • (;(,.i.,])&.>i.7) 计算全套(我相信这部分可以进一步打高尔夫球。如果您知道怎么做,请这样做...)
  • -. 是“设置减去”
  • /:~"1 订购每个输入

在线尝试!

原版的

在线尝试!

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

(;(,.i.,])&.>i.7)保存2(
取消

@FrownyFrog谢谢,更新。
约拿(Jonah)

1

Python 2,89 86字节

通过简化多米诺骨牌集的生成节省了几个字节。

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}

在线尝试!

以[[00],“ 10”,“ 02]之类的字符串列表作为多米诺骨牌的参数,返回python set对象,它们是无序的不同列表。

说明

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

0

Haskell,65个字节

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

用法示例:

*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"]

a在外循环中迭代从0到的所有数字,6b在内循环中迭代在从到的所有数字a6并保留输入字符串ab中既ab没有ba找到也没有找到的那些数字。


0

严重的是16个字节

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

将输入作为字符串列表,将输出字符串列表

在线尝试!

说明:

,`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)

实际上,13个字节(非竞争)

♂S7r;∙`εjS`M-

这与“认真回答”相同(隐式输入除外,这是♂S缩短每个输入字符串的较短方法)。

在线尝试!


1
您的输出中有重复项
Digital Trauma

@DigitalTrauma这是由于自发布以来进行的向后不兼容更改。
Mego

0

球拍

(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))))

2
很高兴看到人们用球拍打高尔夫球!这是一个代码问题,因此您可能应该在答案中包括字节数。您当然也可以从此答案中删除很多空白。
小麦巫师

我同意@WW,因为此答案似乎不够有效。
乔纳森·弗雷希
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.