Command Line Domino Game


  • 0
    S

    Given a file of 'dominos' link them together sequentially in the order they are given, and print out your progress at each step.

    A domino is a square split into quadrants, where each quadrant has a number from 0 to 9.

    A domino can connect if at least two of its quadrants match quadrants on adjacent dominos, but all adjacent quadrants have to match.

    Dominos can be rotated, and the inputs are always designed so there is only one place a domino will fit. Dominos are separated by a blank line in the input file.

    Example inputs:

    dominos1.txt
    ----------
    11     // domino 1
    23
    
    44     // 2
    11
    
    16     // 3
    36
    
    51     // 4
    71
    
    46     // 5
    26
    
    14     // 6
    68
    
    node test.js dominos1.txt prints:
    6 tiles
    link 1
    11
    23
     
    link 2
    44
    11
    11
    23
     
    link 3
    44
    11
    1116
    2336
     
    link 4
      44
    5111
    711116
      2336
     
    link 5 // note this tile had to be rotated 180 degrees clockwise
      44
    5111
    71111662
      233664
     
    link 6 // note this tile had to be rotated 270 degrees clockwise
      4448
    511116
    71111662
      233664
     
     
    dominos2.txt
    ----------
    12	// 1
    34
    
    36	// 2
    15
    
    56	// 3
    78
    
    78	// 4
    90
    
    46	// 5
    26
    
    88	// 6
    01
    
    93	// 7
    54
    
    
    node test.js dominos2.txt prints:
    7 tiles
    link 1
    12
    34
    
    link 2 // note this tile had to be rotated 180 degrees clockwise
    5112
    6334
    
    link 3 // note this tile had to be rotated 90 degrees clockwise
    755112
    866334
    
    link 4 // note this tile had to be rotated 90 degrees clockwise
    97755112
    08866334
    
    link 5 // note this tile had to be rotated 270 degrees clockwise
    97755112
    08866334
       66
       42
    
    link 6 // note this tile had to be rotated 90 degrees clockwise
    97755112
    08866334
    08 66
    18 42
    
    link 7 // note this tile had to be rotated 270 degrees clockwise
    97755112
    08866334
    08 66 34
    18 42 95
    
    
    
    dominos3.txt
    ----------
    11     // 1
    12
    
    12     // 2
    93
    
    93     // 3
    99
    
    39     // 4
    98
    
    95     // 5
    86
    
    57     // 6
    66
    
    77     // 7
    57
    
    13     // 8
    24
    
    45     // 9
    47
    
    24     // 10
    39
    
    
    node test.js dominos3.txt
    10 tiles
    link 1
    11
    12
     
    link 2
    11
    12
    12
    93
     
    link 3
    11
    12
    12
    93
    93
    99
     
    link 4
    11
    12
    12
    93
    9339
    9998
     
    link 5
    11
    12
    12
    93
    933995
    999886
     
    link 6
    11
    12
    12
    93
    93399557
    99988666
     
    link 7
    11
    12
    12    77
    93    57
    93399557
    99988666
     
    link 8
    1113
    1224
    12    77
    93    57
    93399557
    99988666
     
    link 9
    1113
    122445
    12  4777
    93    57
    93399557
    99988666
     
    link 10
    1113
    122445
    12244777
    9339  57
    93399557
    99988666

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.