39
\$\begingroup\$

Challenge

Given two digits 0-9 as input, output a domino (from the double-nine domino set) with these number of pips (dots) on the two faces. The ten possible faces look like this (separated by pipes):

     |     |    o|    o|o   o|o   o|o o o|o o o|o o o|o o o
     |  o  |     |  o  |     |  o  |     |  o  |o   o|o o o
     |     |o    |o    |o   o|o   o|o o o|o o o|o o o|o o o

Or on separate lines:

     
     
     
-----
     
  o  
     
-----
    o
     
o    
-----
    o
  o  
o    
-----
o   o
     
o   o
-----
o   o
  o  
o   o
-----
o o o
     
o o o
-----
o o o
  o  
o o o
-----
o o o
o   o
o o o
-----
o o o
o o o
o o o

Input formats

You may take input in any reasonable format, including but not limited to:

  • Two separate integers, strings, or singleton arrays;
  • A single integer from 0-99;
  • An array of two integers;
  • A string of two digits.

Output formats

  • The two faces may be horizontally aligned, separated by pipes like so:
    o|o   o
     |  o  
o    |o   o
  • Or they may be vertically aligned, separated by hyphens like so:
    o
     
o    
-----
o   o
  o  
o   o
  • You may output a border around the domino if you wish.
  • You may also choose to output a list of lines, a list of the two faces, or a combination of these.
  • You may use any non-whitespace character for the pips (I used o).
  • If you really wish, you can use 0 for whitespace and 1 for the pips, or False/True (or your language's equivalent) if outputting an array.
  • You may remove the whitespace between columns; this is a valid output for 7, 7:
ooo|ooo
 o | o 
ooo|ooo
  • Any of the faces may be rotated by 90 degrees. This is also a valid output for 7, 7:
o   o|o o o
o o o|  o  
o   o|o o o
  • You may have as much/little leading/trailing whitespace as you like, as long as the main part of the output still fits the other constraints.
  • Each face must be 3 lines tall, even if the lines are empty. For 0, 1 you could not output this:
-----

  o

But you could output this:




-----

  o

Similarly, if you were outputting a list of two lists of lines, you could do [["", "", ""], ["", " o", ""]], but not [[""], [" o "]].

Scoring

This is , so the shortest code in bytes in each language wins.

\$\endgroup\$
5
  • \$\begingroup\$ So, for input [2, 1], I could output [[[0,0,1],[0,0,0],[1,0,0]],[[0,0,0],[0,1,0],[0,0,0]]]? \$\endgroup\$
    – Dennis
    Commented Dec 23, 2017 at 2:42
  • \$\begingroup\$ @Dennis Correct. \$\endgroup\$ Commented Dec 23, 2017 at 2:44
  • 2
    \$\begingroup\$ Does the separator between the faces have to be dashes, or can it be some other consistent value? \$\endgroup\$
    – Jo King
    Commented Dec 24, 2017 at 3:40
  • \$\begingroup\$ @JoKing I'll say you can use any consistent character other than the ones you're already using. \$\endgroup\$ Commented Dec 24, 2017 at 16:22
  • \$\begingroup\$ [0,5,21,29,31] are all important numbers here my friends. \$\endgroup\$ Commented Jan 24, 2018 at 21:28

26 Answers 26

16
\$\begingroup\$

Python 2, 101 97 92 68 64 bytes

lambda*a:[[[n>3,n>5,n>1],[n>7,n%2,n>7],[n>1,n>5,n>3]]for n in a]

Try it online!

Credits

\$\endgroup\$
7
  • \$\begingroup\$ @Mr.Xcoder Updated again. \$\endgroup\$
    – Neil
    Commented Dec 23, 2017 at 7:53
  • 1
    \$\begingroup\$ The formatting is optional. Returning a pair of matrices saves at least 22 bytes. \$\endgroup\$
    – Dennis
    Commented Dec 23, 2017 at 14:01
  • 1
    \$\begingroup\$ 68 bytes with no formatting (note that 0 and False are equal in Python, so it should be OK). \$\endgroup\$ Commented Dec 23, 2017 at 15:20
  • \$\begingroup\$ @JonathanAllan Very clever, updated. \$\endgroup\$
    – Neil
    Commented Dec 23, 2017 at 18:05
  • \$\begingroup\$ 64 bytes. If you have to make a lambda, a list comprehension's probably shorter. \$\endgroup\$ Commented Dec 24, 2017 at 12:05
13
\$\begingroup\$

C (gcc), 252 242 269 262 241 235 220 bytes

I was on stack overflow for sockets in python, when this popped up, said why not? first code golf, so i'm not entirely sure if I followed the rules 100% (and if not and someone wants to steal my proverbial cookie and fix it, so be it). With 'o' and ' ', 255 245 272 265 244 238 228 bytes. replace +48 with *79+32.

#define Q(P,R)(R>>P&1)+48
char a[11];i=0;f(char*c){char b=c[0];a[3]=a[7]='\n';a[5]=Q(0,b);a[1]=a[9]=Q(3,b);a[2]=a[8]=Q(2,b)|a[1];a[0]=a[10]=Q(1,b)|a[2];a[4]=a[6]=a[1]|Q(2,b)&Q(1,b);puts(a);if(i++<1){puts("---");f(c+1);}}

Try it online!

How it works:
I use a bit shift and bitwise and to find if a spot should be clear or a pip, then offset the 0 or 1 to the correct ASCII value. it messes up on 4 and 5, so they needed some fixing. actually added a few bytes. was able to remove several bytes by removing a mask and just using 1 (doh)

Special thanks to Mr. Xcoder for the 7 less bytes by removing an excess #define
Changes: removed memset -21 bytes. redid the bit logic for 6, 4, 2 to depend on 8|4&2, 8|4, 8|4|2, respectively. -6 bytes. removed extra newlines by using puts instead of printf, which is also shorter. shortened the array to 11, removing extra assignment. -15 bytes. NOW I think that's the best I can do.

\$\endgroup\$
6
  • 7
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$
    – Shaggy
    Commented Dec 23, 2017 at 9:50
  • \$\begingroup\$ Hi, welcome to PPCG! You can shorten your code a bit further, 245 bytes \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 23, 2017 at 9:51
  • \$\begingroup\$ '\n' can be replaced by 10. (because in C, char data types are also integer data types) Some char can probably be replaced by int. (or omit entirely) \$\endgroup\$
    – user202729
    Commented Dec 23, 2017 at 11:44
  • \$\begingroup\$ Down to 184 bytes here but that's still more than the current c golf, so. \$\endgroup\$ Commented Dec 23, 2017 at 22:02
  • \$\begingroup\$ 173 \$\endgroup\$ Commented Dec 23, 2017 at 22:19
10
\$\begingroup\$

Jelly, 20 bytes

“¤o.ƤẸʠṚ’B¬s5ŒBị@s€3

Try it online!

Alternate version, original output, 33 32 31 bytes

“¤o.ƤẸʠṚ’ṃ⁾ os5ŒBị@s€3K€€Zj€”|Y

Thanks to @user202729 for golfing off 1 byte!

Try it online!

How it works

First, “¤o.ƤẸʠṚ’ – an integer literal in bijective base 250 – sets the return value to 1086123479729183.

Then, converts the return value to binary and takes the logical NOT of each digit, yielding the array

00001001000010110100101011110011101111101111100000

Next, s5ŒB splits that array into chunks of length 5, then bounces each chunk, turning abcde into abcdedcba, yielding

000010000 001000100 001010100 101000101 101010101

111000111 111010111 111101111 111111111 000000000

Now, ị@ retrieves the jth and kth item of this array, where j, k is the program's first argument. Note that indexing is 1-based and modular, so the zeroth element is also the tenth.

Finally, s€3 splits each chunk of length nine into three chunks of length three.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Still looks like magic to me, but I appreciate the attempt at an explanation. I will admit the fault is probably mine as I am just a lowly PHP web developer \$\endgroup\$ Commented Dec 23, 2017 at 6:37
  • \$\begingroup\$ The 3 is using 0 for the pips, not 1 like all the others. \$\endgroup\$ Commented Dec 23, 2017 at 13:28
  • \$\begingroup\$ “¤o.ƤẸʠṚ’ should work. \$\endgroup\$ Commented Dec 23, 2017 at 13:41
  • \$\begingroup\$ @JonathanAllan Thanks! Not sure how that happened... \$\endgroup\$
    – Dennis
    Commented Dec 23, 2017 at 13:48
9
\$\begingroup\$

Jelly, 13 bytes

⁽½ÑD<;ḂŒBs3µ€

Try it online!

Combining Dennis' idea of using ŒB (bounce) in this answer and Xcali's observation in this answer to get 13 bytes.


Jelly, 28 bytes

(with pretty printing)

Only now do I know that Jelly string literal is automatically terminated...

⁽½ÑD<;ḂŒBị⁾o Ks6Yµ€j“¶-----¶

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Apparently my approach ⁽½ÑD leads to less bytecount than EriktheOutgolfer's answer “¤¦¢¬‘ here \$\endgroup\$
    – user202729
    Commented Dec 23, 2017 at 12:51
  • \$\begingroup\$ Wouldn't it be best to reorder the functions so the 13 bytes (outgolfing Dennis) is up top and can be seen more easily? \$\endgroup\$
    – Adalynn
    Commented Dec 23, 2017 at 17:28
  • \$\begingroup\$ @Zacharý Temporary solution. Will fix it later. \$\endgroup\$
    – user202729
    Commented Dec 24, 2017 at 0:43
9
\$\begingroup\$

Perl 5, 107 76 70 67 + 1 (-a) = 67 bytes

$,="
---
";say map{'351
7 7
153'=~s/\d/$_>$&||0/ger=~s/ /$_%2/er}<>

Try it online!

Uses 0 for whitespace and 1 for pips. Pretty simple method: observe that as the digit goes up, once a pip is "on", it never goes "off," except for the one in the middle. In the middle position, it is on for all odd numbers. Thus, for each position, it's a simple matter of checking if the digit is greater than the last digit for which it is off. The ||0 creates output when the condition is false. In Perl, false is undef which outputs as null.

\$\endgroup\$
1
  • \$\begingroup\$ Nice answer! You can save a couple more bytes too, using map...,<> and |0 (instead of ||0) \$\endgroup\$ Commented Dec 13, 2023 at 22:03
6
\$\begingroup\$

PHP 155, 150 bytes

function d($a){foreach($a as$n){$o="---";for($i=0;$x=2**$i,$i<9;++$i)$o.=([0,16,68,84,325,341,365,381,495,511])[$n]&$x?0:' ';echo chunk_split($o,3);}}

It takes an array of integers as the input. For testing:

d([1,2]);

echo "=========\n";

d([0,1,2,3,4,5,6,7,8,9]);

Output Format:

---
   
 0 
   
---
  0
   
0  

Check it out live here

My Solution

For my solution I used a matrix consisting of bitwise numbers ( powers of 2 ). It can be visualized like this:

 1  |  2  |  4
 8  | 16  | 32
 64 | 128 | 256

And then a storage array consisting of the bit positions for the pips of each domino correlated by the numbered index:

[0,16,68,84,325,341,365,381,495,511]

So just to clarify:

  • example 0: index 0 or value 0 would be the blank domino, which is always false.
  • example 1: index 1 or value 16 would be the number one domino and in the matrix that is in the center 16.
  • example 2: index 2 or value 68 would be the number two domino and in the matrix that is top right 4 and bottom left 64 or 4|64
  • example 3: index 5 or value 341 would be the number five domino and in the matrix that is 1|4|16|64|256
  • example 4: index 9 or value 511 would be the number nine domino and in the matrix its the combination of all the bits.

Once that is established it's a fairly simple matter of looping for the 9 positions in the matrix, and setting $x to 2 to the power of $i

for($i=0;$x=2**$i,$i<9;++$i)

Then we do a bitwise And & as we iterate through those spots. So for examples sake will use example 2 from above and I will use x's instead spaces for sake of visual clarity:

  • iteration 1, 68 & 1 ? 0 : 'x' which results in 'x'
  • iteration 2, 68 & 2 ? 0 : 'x' which results in 'x'
  • iteration 3, 68 & 4 ? 0 : 'x' which results in 0
  • iteration 4, 68 & 8 ? 0 : 'x' which results in 'x'
  • iteration 5, 68 & 16 ? 0 : 'x' which results in 'x'
  • iteration 6, 68 & 32 ? 0 : 'x' which results in 'x'
  • iteration 7, 68 & 64 ? 0 : 'x' which results in 0
  • iteration 8, 68 & 128 ? 0 : 'x' which results in 'x'
  • iteration 9, 68 & 256 ? 0 : 'x' which results in 'x'

When the loop is complete we wind up with this string "xx0xxx0xx".

Then we add the border "---xx0xxx0xx" to it ( I actually start with the border, but whatever).

And finally we chunk_split() it on 3's for:

---
xx0
xxx
0xx

Feel free to let me know what you think.

\$\endgroup\$
5
  • \$\begingroup\$ You can shorten it even further by using the exponentiation operator ** introduced in PHP 5.6 instead of pow() php.net/manual/en/language.operators.arithmetic.php \$\endgroup\$
    – Daniel
    Commented Dec 25, 2017 at 19:28
  • \$\begingroup\$ @Daniel - Thanks saved 5 bytes! I wasn't aware they added that, I always try to use the ^ but its the bitwise XOR ... lol \$\endgroup\$ Commented Dec 25, 2017 at 19:50
  • \$\begingroup\$ I don't think you are allowed to print an extra border. \$\endgroup\$
    – 12Me21
    Commented Jan 29, 2018 at 16:13
  • \$\begingroup\$ show me where it even remotely hints at that in the OP. \$\endgroup\$ Commented Jan 29, 2018 at 18:38
  • \$\begingroup\$ I guess this would be shorter operating on $argv. The function overhead in PHP is usually 13 bytes. \$\endgroup\$
    – Titus
    Commented Feb 18, 2018 at 22:58
6
\$\begingroup\$

JavaScript (ES6), 79 78 bytes

Saved 1 byte thanks to @ETHproductions

Takes input in currying syntax (a)(b) and outputs a vertical ASCII domino.

a=>b=>(g=n=>`351
707
153`.replace(/./g,d=>' o'[(+d?n>d:n)&1]))(a)+`
---
`+g(b)

Demo

let f =

a=>b=>(g=n=>`351
707
153`.replace(/./g,d=>' o'[(+d?n>d:n)&1]))(a)+`
---
`+g(b)

console.log(f(4)(2))
console.log(f(3)(7))


Horizontal version, 80 79 bytes

Saved 1 byte thanks to @ETHproductions

Takes input as an array of 2 integers and outputs a horizontal ASCII domino.

a=>`240|351
686|797
042|153`.replace(/\d/g,d=>' o'[(d<8?(x=a[d&1])>(d|1):x)&1])

Demo

let f =

a=>`240|351
686|797
042|153`.replace(/\d/g,d=>' o'[(d<8?(x=a[d&1])>(d|1):x)&1])

console.log(f([4,2]))
console.log(f([3,7]))

\$\endgroup\$
2
  • \$\begingroup\$ Nice, very similar to what I had. Save a byte with either n>d|0 or (+d?n>d:n)&1 \$\endgroup\$ Commented Dec 23, 2017 at 15:52
  • \$\begingroup\$ Whoa, I had no idea .replace() could take a function as a replacement. I learn some cool things around here. :) \$\endgroup\$ Commented May 26, 2020 at 2:04
4
\$\begingroup\$

APL (Dyalog), 25 bytes

2∘|(3 3⍴⊢,,∘⌽)¨>∘3 5 1 7¨

Try it online!

-2 thanks to ngn.

The output format is a little bit weird: this function returns an array containing two shape-3,3 arrays each containing 0s and 1s.

\$\endgroup\$
2
  • \$\begingroup\$ a rewrite for -2 bytes: 2∘|(3 3⍴⊢,,∘⌽)¨>∘3 5 1 7¨ \$\endgroup\$
    – ngn
    Commented Dec 27, 2017 at 11:07
  • \$\begingroup\$ @ngn thanks, that's clever :p \$\endgroup\$ Commented Dec 27, 2017 at 12:27
4
\$\begingroup\$

C (gcc), 115 113 bytes

-2 bytes thanks to ceilingcat

i;g(x){for(i=0;9/++i;)printf("%c%c",32+(i^5?x>" CEAG@GAEC"[i]%8:x%2),i%3?32:10);}f(a,b){g(a),puts("-----"),g(b);}

Try it online!

\$\endgroup\$
0
2
\$\begingroup\$

Javascript (ES6), 87 bytes

a=>b=>[(s=n=>[[n>3,n>5,n>1],[n>7,n%2,n>7],[n>1,n>5,n>3]].map(c=>c.map(b=>+b)))(a),s(b)]

f=a=>b=>[(s=n=>[[n>3,n>5,n>1],[n>7,n%2,n>7],[n>1,n>5,n>3]].map(c=>c.map(b=>+b)))(a),s(b)]
<div oninput="o.innerText=JSON.stringify(f(a.value)(b.value))"><input id=a type=number min=1 max=9 value=1><input id=b type=number min=1 max=9 value=1><pre id=o>

\$\endgroup\$
1
  • \$\begingroup\$ Nice DOMinoes... \$\endgroup\$ Commented Jan 24, 2018 at 19:48
2
\$\begingroup\$

Haskell - 88 characters

map$zipWith(zipWith($))[[(>4),(>5),(>1)],[(>7),odd,(>7)],[(>1),(>5),(>3)]].repeat.repeat

Takes a list of two numbers indicating the faces, returns a list of list of list of bool. Not that short but I find the solution interesting.

\$\endgroup\$
2
  • \$\begingroup\$ You can just use map instead of repeat and zipWith: map$(<$>[[(>4),(>5),(>1)],[(>7),odd,(>7)],[(>1),(>5),(>3)]]).map.flip($)Try it online! \$\endgroup\$
    – Laikoni
    Commented Dec 27, 2017 at 11:20
  • \$\begingroup\$ Non-pointfree saves two more bytes: Try it online! \$\endgroup\$
    – Laikoni
    Commented Dec 27, 2017 at 11:38
2
\$\begingroup\$

Jelly, 16 bytes

>⁽¤xb8¤;ḂŒḄs3
Ç€

Try it online!

Used Neil's strategy and base decompression to generate the values; outputs as a binary array. Takes a list as input.

Explanation:

Ç€
 € for €ach input,
Ç  execute the previous line.

>⁽¤xb8¤;ḂŒḄs3
 ⁽¤xb8¤       the array [3, 5, 1, 7]
>             1 if the input is greater than each element, 0 otherwise
       ;Ḃ     append input % 2
         ŒḄ   bounce array
           s3 split into chunks of 3
\$\endgroup\$
2
+50
\$\begingroup\$

Pip, 32 27 24 21 bytes

-3 bytes thanks to @DLosc

FcgP[Yc>_M3517c%2RVy]

Try it online!

Explanation:

F                      For each
 c                       character $c
  g                      in the list of inputs:
   P                     Print
    [               ]      an array consisting of
                             an array of bits representing whether
      c>                       $c is greater than
        _M                       each of
          3517                     3, 5, 1, and 7
     Y                       (call this bit array $y),
              c%2            $c mod 2,
                 RV          and the reverse
                   y           of $y.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Congratulations on winning the Pip bounty! Now that the bounty period is over, I can tell you: save 3 bytes by mapping to a scalar 3517 instead of a list [3 5o7]. ;) \$\endgroup\$
    – DLosc
    Commented Jan 29, 2018 at 19:35
1
\$\begingroup\$

><>, 57+3 = 60 bytes

>{:3)$:5)$:1)$:7)$:2%$\ao \
\?%cl999)3$)5:$)1:$)7:/nnn<rp

Try It Online. Outputs as a vertical domino with 1s for dots, 0s for whitespace and 9s for separators like so:

001
000
100
999
111
111
111

Technically this can be extended to up to 12 inputted values.

Old Version:

><>, 76+3 = 79 bytes

>{:3)$:5)$:1)$a$:7)$:2%$:7)\&?o~?!n\
\?(*a3la"---"a)3$)5:$)1:$a$/$&:)9::<r~p

Try It Online. Outputs as a vertical domino with 1s for dots and 0s for whitespace like so:

001
000
100
---
111
111
111
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 46 44 43 39 bytes

EE²℅§@APQTUVW^_NE⪪E⁹§ o÷ιX²↔⁻⁴λ³⪫λ M⁵↑⁵

Try it online! Link is to verbose version of code. Explanation:

EE²℅§@APQTUVW^_N

Read two integers and map them in the lookup table. Then map over the result. (This effectively captures the result in a temporary.)

  E⁹                Loop `l` (!) from 0 to 8
            ⁻⁴λ     Subtract from 4
           ↔        Absolute value
         X²         Power of 2
       ÷ι           Divide into the looked-up value `i`
    § o             Convert to space or o
 ⪪             ³    Split into (3) groups of 3
E                   Map over each group
                ⪫λ  Join the 3 characters with spaces

The results are then implicitly printed on separate lines, with an extra blank line between each face because the results are nested.

M⁵↑⁵

Move up and draw the dividing line in between the faces.

Previous 43-byte horizontal version:

↶P³M⁷←FE²℅§@APQTUVW^_NF⁹«F¬﹪κ³⸿⸿§ o÷ιX²↔⁻⁴κ

Try it online! Link is to verbose version of code. Explanation:

Work vertically.

P³

Print the dividing line.

M⁷←

Position to the start of the first face.

FE²℅§@APQTUVW^_N

Read two integers and map them in the lookup table.

F⁹«

Prepare to output up to 9 os.

F¬﹪κ³⸿⸿

But start a new column every three os.

§ o÷ιX²↔⁻⁴κ

Convert the lower 5 bits of the ASCII code to binary, and then mirror the output for the remaining 4 os.

\$\endgroup\$
8
  • \$\begingroup\$ The output format is rather liberal, which should save a few bytes. \$\endgroup\$
    – Dennis
    Commented Dec 23, 2017 at 2:38
  • 1
    \$\begingroup\$ What is this witchcraft \$\endgroup\$ Commented Dec 23, 2017 at 2:47
  • \$\begingroup\$ @Dennis Actually the original output format is the most helpful, as it automatically gives me room to draw the dividing line. \$\endgroup\$
    – Neil
    Commented Dec 23, 2017 at 12:08
  • \$\begingroup\$ Oh god, there are two Neils. \$\endgroup\$
    – Adalynn
    Commented Dec 23, 2017 at 17:19
  • 2
    \$\begingroup\$ @Zacharý Actually according to the user page there are eight, or 40 if you include people whose names contain Neil... \$\endgroup\$
    – Neil
    Commented Dec 23, 2017 at 19:37
1
\$\begingroup\$

Chip, 142 135 bytes

! CvDvB
>v-]-x.
|Z-]-]e
|Z]xe|
|ZR(-'
|Zx.AD
|Zxx]x.
|Zx^-]e
|Z<,(-.
|Zx]xe|
|Zx-]-]e
|Zx-]-x'
|Z<C^D^B
|>x~s
|Zx.
|Zx<
|Zxb
|Z+^~f
`zd

Try it online!

Input is a string of digits. Uses zeroes as the pips. Draws the pips for one number, reads next input byte. If no next byte, terminate, else draw the divider and go to start.

Each Z (or z) corresponds to one character of output, they are positioned to fire in order top to bottom. The capitalized A, B, C, and D correspond to the low four bits of the input (that's all we look at, so "34" == "CD" == "st" ...). The lowercase b, d, e, f correspond to various bits of the output.

Can make infinite-length dominoes too; try giving 0123456789 as input.

\$\endgroup\$
1
\$\begingroup\$

C (gcc), 150 146 145 bytes

#define p(x)printf(" %c",33-(x)),
P(a){p(a<4)p(a<6)p(a<2)p(23)p(a<8)p(~a&1)p(a<8)p(23)p(a<2)p(a<6)p(a<4)p(23)0;}f(a,b){P(a),puts(" -----"),P(b);}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ @ceilingcat Thank you. \$\endgroup\$ Commented Aug 25, 2019 at 10:33
  • \$\begingroup\$ @ceilingcat Thankss again. \$\endgroup\$ Commented May 26, 2020 at 0:37
1
\$\begingroup\$

Javascript (ES5), 103 characters

(a,b,h=(y=7)=>
  ' o   o ooo'.slice(+y,+y+3))=>
    ['223355','242424245','221155'].map(z=>
      h(z[a])+'|'+h(z[b]))

Linebreaks and whitespace inserted for readability.

\$\endgroup\$
0
\$\begingroup\$

APL+WIN, 49 47 bytes

4⌽'|',⌽⍉6 3⍴,⍉(9⍴2)⊤(+\∊0 241 52 24 114,¨16)[⎕]

Edited as per Adam's comment, thanks, to run with index origin zero.

Prompts for screen input as a vector of integers one for each face.

The output is of the form:

1 1 1 | 0 0 1    0 0 0 | 1 0 1
0 1 0 | 0 1 0    0 0 0 | 0 1 0
1 1 1 | 1 0 0    0 0 0 | 1 0 1

for an inputs of 7 3 and 0 5

Explanation:

(+\∊0 241 52 24 114,¨16) create a vector of integers whose binaries
                         represent the dots on the domino faces

[1+⎕] take input integers as indices to select from above vector

⍉6 3⍴,⍉(9⍴2)⊤ convert selected integers to a 9x2 binary matrix and reshape
              to match the orientation of the domino faces

4⌽'|',⌽ rotate, concatenate centre line markers and rotate again to centre 
\$\endgroup\$
2
  • \$\begingroup\$ Why not use ⎕IO←0 to save yourself the 1+? \$\endgroup\$
    – Adám
    Commented Dec 24, 2017 at 11:07
  • \$\begingroup\$ @Adam Why not indeed - lazy ;) \$\endgroup\$
    – Graham
    Commented Dec 24, 2017 at 11:29
0
\$\begingroup\$

Python 2, 121 bytes

lambda x,y,d="001155777702020202570044557777":[("%03d"%int(bin(int(o))[2:]),"---")[o=="3"]for o in d[x::10]+"3"+d[y::10]]

Try it online!

Reduced to 121 using a lambda after going back and re-reading the rules. Now outputs a list of lines.

Previous version with nicely formatted output:

Python 2, 156 153 147 141 bytes

x,y=input()
d="001155777702020202570044557777"
a=["%03d"%int(bin(int(o))[2:])for o in d[x::10]+d[y::10]]
for x in a[:3]+["---"]+a[3:]:print x

Try it online!

-3 with thanks to @NieDzejkob

Takes input as 2 integers and outputs in vertical format with 0=space and 1=dot.

\$\endgroup\$
1
  • \$\begingroup\$ 153 bytes \$\endgroup\$
    – Maya
    Commented Dec 24, 2017 at 8:17
0
\$\begingroup\$

Pyt, 220 154 bytes

Second attempt (154 bytes)

46281ᴇ8264áĐ9ř3%¬Đ¬2⁵*⇹1ᴇ*+03Ș←Đ3Ș≥Đ6²⁺3**⇹¬2⁵*+⇹9ř5=⇹2%*9²2-*+⇹9ř9<*Ž⇹ŕ⇹9ř3%¬Đ¬2⁵*⇹1ᴇ*+03Ș←Đ3Ș≥Đ6²⁺3**⇹¬2⁵*+⇹9ř5=⇹2%*9²2-*+⇹9ř9<*Ž⇹ŕ5⑴9△*Ƈǰ⇹Ƈǰ64ȘƇǰ6↔ŕ↔ŕ↔

Explanation:

46281ᴇ8264áĐ                                    Pattern matching for every cell but the middle
9ř3%¬Đ¬2⁵*⇹1ᴇ*+03Ș                              Non-pip characters
←Đ3Ș≥Đ6²⁺3**⇹¬2⁵*+⇹9ř5=⇹2%*9²2-*+⇹9ř9<*Ž⇹ŕ⇹     Make top cell
9ř3%¬Đ¬2⁵*⇹1ᴇ*+03Ș                              Non-pip characters
←Đ3Ș≥Đ6²⁺3**⇹¬2⁵*+⇹9ř5=⇹2%*9²2-*+⇹9ř9<*Ž⇹ŕ      Make bottom cell
5⑴9△*Ƈǰ⇹Ƈǰ64ȘƇǰ6↔ŕ↔ŕ↔                          Make boundary and combine



First attempt (220 bytes):

2`↔←Đ4≥Đ6²⁺3**⇹¬5«+2⁵⇹3ȘĐ6≥Đ6²⁺3**⇹¬5«+2⁵⇹3ȘĐ2≥Đ6²⁺3**⇹¬5«+1ᴇ⇹3ȘĐ8≥Đ6²⁺3**⇹¬5«+2⁵⇹3ȘĐ2%Đ6²⁺3**⇹¬5«+2⁵⇹3ȘĐ8≥Đ6²⁺3**⇹¬5«+1ᴇ⇹3ȘĐ2≥Đ6²⁺3**⇹¬5«+2⁵⇹3ȘĐ6≥Đ6²⁺3**⇹¬5«+2⁵⇹3Ș4≥Đ6²⁺3**⇹¬5«+1ᴇ9△ĐĐĐĐ1ᴇ↔⁻łŕ↔ŕŕŕŕŕŕáƇǰ

Explanation:

2                           Push 2 (this is how many 'cells' to make)
`     ... ł                 While the top of the stack is not zero, loop
↔                           Flip the stack (useless at the beginning, undoes the flip at the end of the loop)
←Đ4≥Đ6²⁺3**⇹¬5«+            Set top-left pip
2⁵⇹3Ș                       Space
Đ6≥Đ6²⁺3**⇹¬5«+             Set top-middle pip
2⁵⇹3Ș                       Space
Đ2≥Đ6²⁺3**⇹¬5«+             Set top-right pip
1ᴇ⇹3Ș                       New line
Đ8≥Đ6²⁺3**⇹¬5«+             Set middle-left pip
2⁵⇹3Ș                       Space
Đ2%Đ6²⁺3**⇹¬5«+             Set center pip
2⁵⇹3Ș                       Space
Đ8≥Đ6²⁺3**⇹¬5«+             Set middle-right pip
1ᴇ⇹3Ș                       New line
Đ2≥Đ6²⁺3**⇹¬5«+             Set bottom-left pip
2⁵⇹3Ș                       Space
Đ6≥Đ6²⁺3**⇹¬5«+             Set bottom-middle pip
2⁵⇹3Ș                       Space
4≥Đ6²⁺3**⇹¬5«+              Set bottom-right pip
1ᴇ                          New line
9△ĐĐĐĐ                      Add 5 dashes
1ᴇ                          New line
↔⁻ł                         Decrement counter (if >0, loop; otherwise, exit loop)
ŕ↔ŕŕŕŕŕŕ                    Remove all unnecessary items on the stack
áƇǰ                         Push stack to an array, get characters at unicode codepoints given by values in the array, join characters with empty string


Try it online!

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 34 bytes

•ΩõIº•R2ô¹2÷è¹È-bDg5s-ú.∞3ô»TR„ o‡

Try it online!


This was difficult because 05AB1E has bad padding.


Basic explanation:

  • There are 4 significant patterns here which are 2, 4, 6 and 8.
  • 3,5,7 and 9 are the other patterns plus 1.
  • 1 is not significant due to symmetry, if the input is even, subtract 1 to toggle the middle bit.
  • Toggling the LSB allows the middle bit to be flipped due to mirroring.
\$\endgroup\$
0
\$\begingroup\$

SmileBASIC, 92 69 bytes

INPUT N,M
DEF Q?N>3;N>5;N>1?N>7;1AND N;N>7?N>1;N>5;N>3
END
Q?777N=M
Q

Example:

? 7,2
111
010
111
777
001
000
100

This is what happens when your rules aren't strict enough.

\$\endgroup\$
0
\$\begingroup\$

FALSE, 116 80 78 70 69 66 63 61 59 58 bytes

[$3[>_$.\$]$p:!5p;!1p;!"
"7p;!%1&.."
"..."
"]$s:!"---
"s;!

still working on this...

\$\endgroup\$
0
\$\begingroup\$

PHP, 116 bytes

while($i<6)echo strtr(sprintf("%03b",[_011557777,_202020267,_044557777][$i/2][$argv[$i%2+1]]),10,"o "),"|
"[$i++%2];

requires PHP 5.5 or later. Run with -nr or try it online.

\$\endgroup\$
0
\$\begingroup\$

Vyxal j, 41 bytes

»⟑-⁰ɖṄwi⁋ǏSżƛ»b9ẇ:£?i¥?i3(2p)Jƛ`o -`$i;3ẇ

Try it Online!

A mess.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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