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
L, and the bottom output
B is another function
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.)
R = 0,
B = 0
R = 1,
B = 1
R = L,
B = T
R = T,
B = L
- Top only:
R = T,
B = T
- Left only:
R = L,
B = L
R = not L,
B = not T
R = L and T,
B = L and T
R = L or T,
B = L or T
R = L xor T,
B = L xor T
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
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
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
01 would have output
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]:
If you wrote a function, you could return the two strings in a tuple or list (or still print them).
- 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
- Your grid must use the proper characters (
0 1+\U)!&|^). Remember that
mean the same thing.
(Read I/O as
1111 1\+\ 1+\+ 1\+\
Any input should result in
Xor from Nand: (note the column of trailing spaces)
\)+\ U&!& +! ! \&!& !
+++\00000000 000\!!!!\000 00000000\+++
The first bit of the left input becomes the last bit of the right output. Everything else is
))) UUU U+U U+U UUU
The first bit of the left input goes to all the outputs.
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.