Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
thanks @DLosc for reminding me I should output spaces between the columns
thanks @coltim for -1 byte
1@"\n"/("# "1_'"1_,/'11,''+'+/''a*')'a*/:\:a:+2!!1_(. 0:"")#3;
Try it online!Try it online!
1@"\n"/"# "1_',/'1,''+/''a*/:\:a:+2!!1_(. 0:"")#3;
Try it online!
1@"\n"/("# "1_,/1,'+/')'a*/:\:a:+2!!1_(. 0:"")#3;
{"# "@+/''a*/:\:a:+2!!x#3}
Try it online! thanks @DLosc for reminding me I should output spaces between the columns
x:2 / for testing x#3 / that many 3s 3 3 !x#3 / all x-tuples of 0 1 2 as a transposed matrix (0 0 0 1 1 1 2 2 2 0 1 2 0 1 2 0 1 2) 2!!x#3 / mod 2 (0 0 0 1 1 1 0 0 0 0 1 0 0 1 0 0 1 0) +2!!x#3 / transpose (0 0 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 0) a*1@"\n"/:\:a:+2!!2#3"# "1_',/ multiplication table (outer product) ((0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 1;0 0;0 0;0 1;0 0;0 0;0 1;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 0;0 0;1 0;1 0;1 0;0 0;0 0;0 0) (0 0;0 1;0 0;1 0;1 1;1 0;0 0;0 1;0 0) (0 0;0 0;0 0;1 0;1 0;1 0;0 0;0 0;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 1;0 0;0 0;0 1;0 0;0 0;0 1;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0)) +'1,''+/''a*/:\:a:+2!!2#3 / sum each each 1_(0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 2 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0. 0) "# "@+/''a*/:\:a:+2!!2#3 / index into "# " (out-of-bounds indexing returns " ") ("#########" "# ## ## #" "#########" "### ###" "# # # #" "### ###" "#########" "# ## ## #" "#########""")#3;
x:2 / for testing x#3 / that many 3s 3 3 !x#3 / all x-tuples of 0 1 2 as a transposed matrix (0 0 0 1 1 1 2 2 2 0 1 2 0 1 2 0 1 2) 2!!x#3 / mod 2 (0 0 0 1 1 1 0 0 0 0 1 0 0 1 0 0 1 0) +2!!x#3 / transpose (0 0 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 0) a*/:\:a:+2!!2#3 / multiplication table (outer product) ((0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 1;0 0;0 0;0 1;0 0;0 0;0 1;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 0;0 0;1 0;1 0;1 0;0 0;0 0;0 0) (0 0;0 1;0 0;1 0;1 1;1 0;0 0;0 1;0 0) (0 0;0 0;0 0;1 0;1 0;1 0;0 0;0 0;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0) (0 0;0 1;0 0;0 0;0 1;0 0;0 0;0 1;0 0) (0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0;0 0)) +/''a*/:\:a:+2!!2#3 / sum each each (0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 2 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0) "# "@+/''a*/:\:a:+2!!2#3 / index into "# " (out-of-bounds indexing returns " ") ("#########" "# ## ## #" "#########" "### ###" "# # # #" "### ###" "#########" "# ## ## #" "#########")