8
\$\begingroup\$

Dialogue by a 3Der.

I was hired by Sr. 4Der to learn the 4D universe and I was willing to get to know more about it. But since I am a 3Der, I wouldn't see him, nor would I know how the real shapes look like. All I can do is illustrate.

Sr. 4Der is pretty much invisible to us. We can't see him, but we can hear his voice. Certainly, he would give us a task for each and one of us.

So I was employed as "Programmer", and the task is to illustrate 4D shapes by the use of ASCII art, and I came up with a design for a tesseract.

       ############################
      ####                       ####
     # #  ##                    # #  ##
    #  #    ##                 #  #    ##
   #   #      ##              #   #      ##
  #    #        ##           #    #        ##
 #     #          ###       #     #          ###
############################      #             ##
###    #              ###  ###    #               ###
#  ##  #                 ###  ##  #                  ##
#    ###                   ##   ###                    ##
#      ##                  # ##   ##                     ##
#      # ##                #   ## # ##                     ##
#      #######################################################
#     # ##    ##           #     ####    ##                 ##
#    #    ##    ###        #    # #  ##    ###             # #
#   #       ##     ##      #   #  #    ##     ##          #  #
#  #          ##     ##    #  #   #      ##     ##       #   #
# #             ##     ##  # #    #        ##     ##    #    #
##                ###    ####     #          ###    ## #     #
#######################################################      #
 ##                    ### ###    #               ### #      #
   ##                     ##  ##  #                  ##      #
     ##                    ###  ###                   ###    #
       ##                  #  ##  ##                  #  ##  #
         ###               #    ### ##                #    ###
            ##             #      ############################
              ###          #     #       ##           #     #
                 ##        #    #          ###        #    #
                   ##      #   #              ##      #   #
                     ##    #  #                 ##    #  #
                       ##  # #                    ##  # #
                         ####                       ####
                           ############################

And after bringing it to the office of our boss, he called on us and we listened the words.

Dear programmers, attention all. I have found a design by [say name here] of a tesseract and I would like every one of you to try and make a program to output the same outline.

A co-worker of mine then said:

Does it have to be only # or another character?

He replied:

Use the character you want to use. Use only one, then print the tesseract with the same character, over and over. Understood?

He nodded and we did our thing. Some did input, some just did the basic, and more. After our hard work, he congratulates us and the day has finished.

Now that I think about it, maybe it's your turn to make the same tesseract.

Objective

  • Given the code block representing the tesseract, replicate the outline with any char you want to use.
  • Do not change the type of tesseract to be made. Keep the same shape and the final output should be the same one in the code block. (Replace the # with what you want, but only a single ASCII character that is not a space)
  • This is a challenge, so the program with the smallest amount of bytes wins!

Bonus Objective (Not needed to complete the challenge)

  • Make a program where the user gives a char input and will be used to output the tesseract outline using the same character. Rules from the original objective is still applied.
\$\endgroup\$
15
  • 2
    \$\begingroup\$ @StackMeter You could, but it wouldn't be very golfy. The point of a kolmogorov complexity challenge is to do it in a cleverer way than just directly printing the string. \$\endgroup\$ – user Apr 2 at 15:11
  • 1
    \$\begingroup\$ I'd recommend against changing the challenge. "Print this string" challenges are perfectly fine, and most answers don't take the approach suggested by StackMeter, simply because it's almost always longer \$\endgroup\$ – caird coinheringaahing Apr 2 at 15:18
  • 2
    \$\begingroup\$ Can the spaces or newlines be replaced, like the #s? \$\endgroup\$ – Makonede Apr 2 at 16:06
  • 6
    \$\begingroup\$ The introduction text is unnecessary and distracts from the point of the challenge. I suggest you keep that to a minimum \$\endgroup\$ – Luis Mendo Apr 2 at 16:39
  • 1
    \$\begingroup\$ Good one! I'll be looking forward to future episodes in this series! \$\endgroup\$ – rm-vanda Apr 2 at 22:38
9
\$\begingroup\$

JavaScript (Node.js), 428 bytes

Uses 0 instead of #.

_=>Buffer('QaV6:)R/rEkQy|:|\\!8GG6Pzy}lO<:xv-q,GoKfhfkci;Br"? &]N9Xx[}~tvc1Z6;%Fq6>DO(9dGs&sG~n@z},=x7]+Qo4y}~8Tr~>45<y#J;_a-^"X=^:?`(8*QQh"GQ.V0>GBpa~ytaJYb^YJdo=/W&59kP#@pZ-pYt-uLLe-lDv/kV|}.ylnY<-$H@G&H{h4PPL%q&7t?1.?t}cI6Fcz-Nvo_wPUPP:Xh|tG0zp)lNIh`Ah-d"t.+0L8&}M6LK.Mr$4rH\'l(x4p4_v|[gdf-~9qo,c{U\\Vw(RCYJrd`^&G[{Tr$PGPkS\'$iaBKm{q').reduce((p,c)=>p*95n+BigInt(c-32),0n).toString(2).match(/.{62}/g).join`
`.split`1`.join` `

Try it online!

Not sure if it was intentional but, contrary to appearances, the tesseract is not symmetrical.

Storing only the upper part and encoding the differences for the lower part would most certainly be more efficient in some languages, but I didn't find a short enough way to do that in JS.

So this is just a binary to base-95 compression for now.

Note: With RegPack, we get 480 bytes. (Not a fully optimized version, but we could only shave a couple of bytes.)

\$\endgroup\$
1
  • \$\begingroup\$ Good job! This is exactly the sort of solution I frequent this site to see \$\endgroup\$ – rm-vanda Apr 2 at 22:38
8
\$\begingroup\$

Ruby, 252 247 bytes

->{r=s=(' '*62+$/)*34
32.times{|i|s[[7,826,853,1672][i/8]+i%8*62,28]="##{(i%8%7<1??#:' ')*26}#"}
96.times{|j|s[q=[70,97,504,531][j/12%4]-603*(k=j/48)+(m=j%12)*63*z=1-k*2]=?#
m<1&&r=1-k
s[q+r-k*t=80>>m-(79>>j/12&1)&1|2,t]=?#*t
r+=z*t
j==5&&r-=1}
s}

Try it online!

The horizontal, vertical and short diagonal lines are fairly straightforward. The long diagonals are more problematic: the two triple # sections are not always in the same place, and the top left long diagonal actually contains a single #. It's difficult to see because it's where it crosses the horizontal line.)

Commented code - original version

->{r=s=(' '*62+$/)*34                             #Make a string s of 34 lines of 62 spaces (also r needs to be initialised to any value to avoid error.) 
32.times{|i|s[[7,826,853,1672][i/8]+i%8*62,28]=   #Draw horizontals and short diagonals as space-filled parallelograms.
  "##{(i%8%7<1??#:' ')*26}#"}                     #In ruby syntax #{} can be used to insert expressions into string literals.
96.times{|j|                                      #Iterate through the corners of the top and bottom parallelograms, drawing verticals and long diagonals.
s[q=[70,97,504,531][j/12%4]+(k=j/48)*-603+        #This expression gives the first cell of each. Ruby string indexes wrap around so -603 gives a negative index for the bottom.
  (m=j%12)*63*z= ~0**k]=?#                        #Draw the upper verticals downwards from the top and the lower ones upwards from the bottom using z= ~0**k to give +1 or -1
m<1&&r=1-k                                        #r is the offset of the diagonals from the verticals. if new diagonal (m=j%12)=0, initialise r to to value for downward or upward drawing.
t=80>>m-(79>>j/12&1)&1|2                          #t=80>>m&1|2 gives the value 2 or 3 for the number of # to be drawn on each line. 79>>j/12&1 offsets m to shift the pattern by 1 on some diagonals.
s[q+r-k*t,t]=?#*t                                 #Plot the right number of #. For bottom up (leftward) drawing an adjustment of k*t is required. 
r+=z*t                                            #Change r by t, in the correct direction (left or right drawing.)
j==5&&r-=1}                                       #The top left diagonal is drawn odd and needs an adjustment of 1 at a certain point.
s}                                                #Return the string.
\$\endgroup\$
1
  • \$\begingroup\$ Very impressive. Well done! \$\endgroup\$ – Eric Duminil Apr 3 at 11:52
8
\$\begingroup\$

Charcoal, 111 84 bytes

F⪫⪪”)¶³6ΠKsv8∨ιm↥Sq3iθ¿⁼p[⪪∕¤⁺WηQDσ⁰”9¦87878≡ι3F”{∨>´↶}⦃α”✳Iκ#✳Iι×#I§⪪”)⧴Z/g↑◨M⸿”²Iι

Try it online! Link is to verbose version of code. Explanation: As @Arnauld points out, the diagram is not quite symmetric; only six of the top left to bottom right lines are the same, and even then they are not mirror images of themselves, although one is a mirror image of the other six. I therefore encoded an Eulerian Cycle using the following integer key:

0 Horizontal line of 28 #s (left to right)
1 Diagonal line of 8 #s (bottom left to top right)
2 Vertical line of 13 #s (bottom to top)
3 Diagonal line of 28 #s (bottom right to top left)
4 Horizontal line of 28 #s (right to left)
5 Diagonal line of 8 #s (top right to bottom left)
6 Vertical line of 13 #s (top to bottom)
7 Diagonal line of 2 #s (top left to bottom right)
8 Horizontal line of 2 #s (left to right)
9 Diagonal line of 6 #s (top left to bottom right)

The last three are combined to create the three styles of top left to bottom right line. (Note that the # counts above assume that the ends of the lines overlap, although the implementation leaves off the last character as the next line will draw it anyway.) The program then consists of a compressed string of coded values and a program to implement each code in turn using a switch statement. Edit: Saved 10 bytes by using 9 to substitute for 87878 and a further 17 bytes by creating a table of amounts to draw for each direction.

If the diagram was perfectly symmetric, then it would be possible in only 80 60 bytes: Try it online! Link is to verbose version of code.

The above diagram could actually be drawn in a single Charcoal command, although that would (if I have calculated correctly) be 515 bytes (slightly less for the asymmetric version). A highly simplified diagram takes only 67 bytes: Try it online! Link is to verbose version of code. Takes the sizes of the four lines as input. I also implemented an Eulerian Cycle algorithm but for a simplified diagram this still was slightly longer at 74 bytes: Try it online! Link is to verbose version of code. If there's an easily describable Eulerian Cycle then I haven't found it.

\$\endgroup\$
6
\$\begingroup\$

Deadfish~, 2090 bytes

{iii}iiccccccci{cc}cccccccc{dd}dddc{ii}iicccccciccccd{cc}cccicccc{dd}dddc{ii}iicccccicdcicdcciccd{cc}icdcicdccicc{dd}dddc{ii}iiccccicdccicdcccciccd{c}cccccccicdccicdccccicc{dd}dddc{ii}iicccicdcccicdcccccciccd{c}ccccicdcccicdccccccicc{dd}dddc{ii}iiccicdccccicdcccccccciccd{c}cicdccccicdccccccccicc{dd}dddc{ii}iicicdcccccicd{c}icccdcccccccicdcccccicd{c}iccc{dd}dddc{ii}iii{cc}ccccccccdccccccicd{c}cccicc{dd}dddc{ii}iiicccdccccicd{c}ccccicccdccicccdccccicd{c}ccccciccc{dd}dddc{ii}iiicdcciccdccicd{c}cccccccicccdcciccdccicd{c}ccccccccicc{dd}dddc{ii}iiicdccccicccd{c}ccccccccciccdcccicccd{cc}icc{dd}dddc{ii}iiicdcccccciccd{c}ccccccccicdciccdccciccd{cc}cicc{dd}dddc{ii}iiicdccccccicdciccd{c}ccccccicdccciccdcicdciccd{cc}cicc{dd}dddc{ii}iiicdcccccci{ccccc}ccccc{dd}dddc{ii}iiicdcccccicdciccdcccciccd{c}cicdccccciccccdcccciccd{c}cccccccicc{dd}dddc{ii}iiicdccccicdcccciccdccccicccdccccccccicdccccicdcicdcciccdccccicccd{c}cccicdcic{dd}dddc{ii}iiicdcccicdccccccciccdccccciccdccccccicdcccicdccicdcccciccdccccciccd{c}icdccic{dd}dddc{ii}iiicdccicd{c}iccdccccciccdccccicdccicdcccicdcccccciccdccccciccdcccccccicdcccic{dd}dddc{ii}iiicdcicd{c}ccciccdccccciccdccicdcicdccccicdcccccccciccdccccciccdccccicdccccic{dd}dddc{ii}iiiccd{c}ccccccicccdcccciccccdcccccicd{c}icccdcccciccdcicdcccccic{dd}dddc{ii}iii{ccccc}cccccdccccccic{dd}dddc{ii}iiciccd{cc}icccdcicccdccccicd{c}cccccicccdcicdccccccic{dd}dddc{ii}iiccciccd{cc}ciccdcciccdccicd{c}cccccccciccdccccccic{dd}dddc{ii}iiccccciccd{cc}icccdccicccd{c}cccccccccicccdccccic{dd}dddc{ii}iiccccccciccd{c}ccccccccicdcciccdcciccd{c}ccccccccicdcciccdccic{dd}dddc{ii}iicccccccccicccd{c}cccccicdccccicccdciccd{c}ccccccicdcccciccc{dd}dddc{ii}ii{c}cciccd{c}cccicdcccccci{cc}cccccccc{dd}dddc{ii}ii{c}ccccicccd{c}icdcccccicdccccccciccd{c}cicdcccccic{dd}dddc{ii}ii{c}ccccccciccdccccccccicdccccicd{c}icccdccccccccicdccccic{dd}dddc{ii}ii{c}ccccccccciccdccccccicdcccicd{c}cccciccdccccccicdcccic{dd}dddc{ii}ii{cc}ciccdccccicdccicd{c}ccccccciccdccccicdccic{dd}dddc{ii}ii{cc}ccciccdccicdcicd{cc}iccdccicdcic{dd}dddc{ii}ii{cc}ccccciccccd{cc}cccicccc{dd}dddc{ii}ii{cc}ccccccci{cc}cccccccc

Uses ! - it's the closest codepoint to .

Try it online!

Uses an alternative python interpreter since the current deadfish~ interpreter uses recursion and crashes on large programs.

\$\endgroup\$
4
  • \$\begingroup\$ You might want to link to a TIO with your good output (with !). Your TIO links produce blank screens. \$\endgroup\$ – Level River St Apr 3 at 1:35
  • \$\begingroup\$ @LevelRiverSt My code with ! crashes TIO - to see it properly, try highlighting the output. \$\endgroup\$ – A username Apr 3 at 1:36
  • \$\begingroup\$ @LevelRiverSt I found someone's non-recursive python interpreter and pasted into TIO. \$\endgroup\$ – A username Apr 3 at 5:12
  • \$\begingroup\$ shorter (partial) deadfish~ interpreter just for fun \$\endgroup\$ – ASCII-only Apr 3 at 8:57
1
\$\begingroup\$

Vyxal j, 274 bytes

»-pṄṗ,₄xW(j
ḋ2¡e¤∆⟩⟑REK₁₍Ḟ⟑£FO∧⁰d⁼•⌊⌈⟑4D0Zʀ1⌈ ±E1¹,ε∩ṙ∇rȦİǑ!ȧ∇ḣ[F₀ġṙ←lSṙ₁Ȯ⁺DṄ4¾₄fλ>⅛⋏⌈~□¹₍Fṗ¹↵AǍṄ9⁰∇ǔW3∧q₍ǐ¶ɾzḞṫ⁋↲₴[÷ḟC½†>~!`Ṡ⁽Qτ⋏kAẆ€3∩
G∴:Ḋ½T«□²Ṡ‟/d⟇/√⌈Ẇ£8…A{⁽°q∷¼∪⟑β₂Ṁ-ṡ€Ṗ∩ṫkİṀ∷₴vċ⋎ċ≈⟇ʁ⁽JMXȧṖ⟑yZ∞b.J^⁽Ḣ²‛ŀ4⅛⁽∵„|ṁ↲j←"n₀∴⁋⟑∨Bø"µ~⁰cẇ⋎¬ȯ×Ġǔ↵Ḋjy⟨#İḣA`∆₄]‟y∆,›[LḢ½?Ḋɾ¡½»
‛# τ34/

Try it Online!

»...»        # Base-255 compressed integer literal
     ‛# τ    # Convert to custom base with key `# `
         34/ # Divide into 34 pieces
             # (j flag) joined by newline. 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy