Duodyadic tiles are kinds of square function blocks that take two inputs, one from their top side and one from their left side, and have two outputs, one on their right side and one on their bottom side. Each of their outputs is a separate function of both of their inputs.
For example, if #
represents a generic tile, the right output R
is a function f
of inputs T
and L
, and the bottom output B
is another function g
of T
and L
:
T
L#R R = f(T, L)
B B = g(T, L)
(The tiles are termed "duo" since there are two functions, and "dyadic" since both functions have two arguments.)
Tiles can then be composed together on a grid, the outputs of one tile going directly into the inputs of the tiles it neighbors. Here for example, the right output of the left #
goes into the left input of the right #
:
AB D = f(f(A, C), B)
C##D E = g(A, C)
EF F = g(f(A, C), B)
You can imagine that given a set of duodyadic tiles, each with specific functionality, complex (and potentially useful) compositions could be made.
In this challenge, we'll only be concerned with the traditional set of ten logic based duodyadic tiles, where all the inputs and outputs are single-bit binary numbers (zeros or ones). We'll use a separate ASCII character to denote each type of tile.
The tile characters and their input-output relations are as follows:
(T
is for top input, L
for left input, R
for right output, B
for bottom output.)
- Zero:
0
orR = 0
,B = 0
- One:
1
→R = 1
,B = 1
- Cross:
+
→R = L
,B = T
- Mirror:
\
→R = T
,B = L
- Top only:
U
→R = T
,B = T
- Left only:
)
→R = L
,B = L
- Not:
!
→R = not L
,B = not T
- And:
&
→R = L and T
,B = L and T
- Or:
|
→R = L or T
,B = L or T
- Xor:
^
→R = L xor T
,B = L xor T
Challenge
Write a program or function that takes in a rectangular grid of the characters 0 1+\U)!&|^
that represents a "circuit" made using the ten logic based duodyadic tiles. You also need to take in two strings of 0
's and 1
's; one will be the left input column and one will be the top input row. Your program/function needs to print/return the bottom output row and the right output column (also in 0
's and 1
's).
For example, in this grid
+++
+++
all the inputs flow straight across the grid to the outputs
ABC
D+++D
E+++E
ABC
so an input of 010
/01
would have output 010
/01
:
010
0+++0
1+++1
010
The exact output of your program would be [bottom output row]\n[right output column]
or [bottom output row]/[right output column]
:
010
01
or
010/01
If you wrote a function, you could return the two strings in a tuple or list (or still print them).
Details
- Take the three inputs as strings in any reasonable manner (preferably in the order grid, top row, left column): command line, text file, sdtin, function arg.
- You can assume the input row and column lengths will match the grid dimensions and will only contain
0
's and1
's. - Your grid must use the proper characters (
0 1+\U)!&|^
). Remember that0
and
Test Cases
(Read I/O as top
/left
→ bottom
/right
.)
Nand:
&!
00
/0
→ 01
/1
00
/1
→ 01
/1
10
/0
→ 01
/1
10
/1
→ 11
/0
All ones:
1111
1\+\
1+\+
1\+\
Any input should result in 1111
/1111
.
Xor from Nand: (note the column of trailing spaces)
\)+\
U&!&
+! !
\&!&
!
00000
/00000
→ 00000
/00000
00000
/10000
→ 00010
/00000
10000
/00000
→ 00010
/00000
10000
/10000
→ 00000
/00000
Zig zag:
+++\00000000
000\!!!!\000
00000000\+++
The first bit of the left input becomes the last bit of the right output. Everything else is 0
.
000000000000
/000
→ 000000000000
/000
000000000000
/100
→ 000000000000
/001
Propagation:
)))
UUU
U+U
U+U
UUU
The first bit of the left input goes to all the outputs.
000
/00000
→ 000
/00000
000
/10000
→ 111
/11111
Here's a pastebin of all 1×1 grid test cases.
Scoring
The shortest submission in bytes wins.
Bonus: What cool "circuits" can you make?
P.S. Don't bother Googling "duodyadic tiles". I made them up yesterday ;D
If you want to discuss expanding this idea into a full-fledged programming language, come to this chatroom.