キューブを作ってみてください!


15

これに基づいて:正方形を作ってみてください!

これを出力する必要があります:

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

「#」は入力に置き換えられます。

「A」を入力すると、次のようになります

  AAAA
 A A A
AAA  A
A A A
AAAA

「&」を入力すると、次のようになります

  &&&&
 & & &
&&&  &
& & &
&&&&

5
まあ、これはやや似ていますが、少なくとも今回はチャコールの3バイトの答えではありません
ニール

1
最後の2行に先行スペースを含めることができ、結果に先行改行を含めることができますか?
-dzaima

3
B³S‖O↗木炭では10バイトの答えに近いかもしれませんが...私はそれを行うのに十分な言語を知らないだけです。炭の場合はこのようなページが本当に必要です。
魔法のタコUr

5
@AAlex Sandbox
xnor

6
私はこれがどのようにスクエア1のduだとは思わない
ルイスメンドー

回答:



12

05AB1E16 15バイト

ð‚•nxвΛ•2вèJ6ô»

オンラインでお試しください!

説明

ð‚                # push the list [<input>,<space>]
  •nxвΛ•          # push the number 816342339
        2в        # convert to list of base 2 digits
          è       # index into the the 2-char string with this list
           J      # join to string
            6ô    # split into pieces of length 6
              »   # join on newlines

1
リスト/番号内の改行をエンコードして、最後の3バイトを保存できますか?
ロッド

@Rodそれははるかに大きな数字で、少なくとも6バイト、さらにリストに改行を含めるための追加の1〜2バイトです
...-ETHproductions

@Rod:このようなことができます。残念ながら、それは少し長くなります。いい考えだ。
エミグナ

1
•nxвΛ•bTRð¹ì‡6ô»...注文の要件が原因で、あなたの音訳はわずかに文字変換されます。入力を暗黙的に取得01して1バイトの文字列を生成する方法を考え出すことができれば、これは13/14バイトのソリューションになります。
魔法のタコUr

1
@carusocomputing •nxвΛ•bT𹫇6ô»またはð«T•nxвΛ•br‡6ô»同じ長さです。
エミグナ

9

Cubix、62バイト

./v<.o;.@?/;w.w;i:::::NrSs::SrSuUS::sN::rS:r:srNr:SrSsNs:::SSv

オンラインでお試しください!そして通訳見てください!

これは、4キューブに適合します。

        . / v <
        . o ; .
        @ ? / ;
        . . w ;
i : : : : : N r S s : : S r S u
U S : : s N : : r S : r : s r N
r : S r S s N s : : : S S v . .
. . . . . . . . . . . . . . . .
        . . . .
        . . . .
        . . . .
        . . . .

I'm not very good at manipulating the direction of the instruction pointer, so I will continue to try and golf this. Both this and my answer here are based on the "Hello, World!' example program using ./v.o;@?/ (on a 3-cube) to recursively print and pop the characters on the stack, so the rest of the code is just pushing the characters onto the stack in the right order.

I have now made a cube on a cube, so I can rest easy (and do my actual work).


8

SOGL, 13 10 bytes

Βū&⁵'r⁹‘6n

Explanation:

Βū&⁵'r⁹‘    push "  ŗŗŗŗ ŗ ŗ ŗŗŗŗ  ŗŗ ŗ ŗ ŗŗŗŗ", where "ŗ" is replaced with input
        6n  split into lines of length 6

1
How is this sitting at 0? Probably due to lack of a TIO ._. +1
Magic Octopus Urn

I think that there's gonna be at (hopefully) most 1 more update breaking stuff and then I'll think about some online running thing
dzaima

6
Son Of a Golfing Language?
ETHproductions

@ETHproductions lol
dzaima

8

MATL, 13 10 bytes

Thanks to Conor O'Brien for removing 3 bytes, and for showing me that unprintables can be used in Octave.

The code contains unprintable characters. Try it online!

Explanation

'....'   % Push 5-char string (contains unprintables). Each char encodes a row
         % of the desired pattern
B        % Convert to binary. Gives a 5×6 binary matrix with the pattern
*        % Implicit input. Multiply element-wise (converts input to ASCII code)
c        % Convert to char. Implicitly display. Char 0 is shown as space

You can make this 10 bytes if you're okay with unprintables. Try it online!
Conor O'Brien

@ConorO'Brien Hey, thanks! I wasn't sure Octave was okay with those... how did you even type them?
Luis Mendo

Well, I honestly I took the numbers, converted them to hex, then did echo 0f15392a3c|xxd -r -p|clip. On windows, clip is the clipboard. Then I just pasted them :P (If you're on a command line, it's ^O^U as well)
Conor O'Brien

@ConorO'Brien That's way over my head. You should really post that as your answer
Luis Mendo

It uses the same tactic as yours does, just removing the need for modulo 64 by using the values directly.
Conor O'Brien


6

Japt, 20 bytes

"OUyj|"®c ¤Åd0S1U +R

Test it online!

Not too bad for a language with no built-in compression (well, except compressing strings of lowercase letters)...

Explanation

In binary, the five characters in the string are:

O 1001111
U 1010101
y 1111001
j 1101010
| 1111100

Slice off the initial 1 from each, and you get the pattern for the cube.

"OUyj|"®   c ¤  Å  d0S1U +R
"OUyj|"mZ{Zc s2 s1 d0S1U +R}  // Expanded
                              // Implicit: U = input string
"OUyj|"mZ{                 }  // Replace each character Z in this string with this function:
          Zc                  //   Take the char-code of Z.
             s2               //   Convert to a binary string.
                s1            //   Slice off the first character (always a "1").
                   d0S1U      //   Replace "0"s with spaces and "1"s with the input.
                         +R   //   Append a newline.
                              // Implicit: output result of last expression

I tried a template-based approach (ll can be compressed), but it's 11 bytes longer.
Luke

Nice. I was down to 23 bytes before I realised I'd made a balls of it!
Shaggy

6

Z80 Assembly, 37 bytes machine code

Assume a memory mapped I/O device:

; DO NOT INPUT A SPACE or it will go into infinite loop printing spaces & newlines!

3A xx xx    ld  a, (input)  ; get input character
11 0A 20    ld  de, 200ah   ; space & newline
21 yy yy    ld  hl, output  ; get output address
4F          ld  c, a        ; put character in c
loop:
72          ld  (hl), d     ; output space * 2       | output character * 2
72          ld  (hl), d
77          ld  (hl), a     ; output character       | output character
71          ld  (hl), c     ; output character * 2   | output space * 2
71          ld  (hl), c
77          ld  (hl), a     ; output character       | output character
73          ld  (hl), e     ; output newline         | output newline
72          ld  (hl), d     ; output space           | output character
71          ld  (hl), c     ; output character       | output space
72          ld  (hl), d     ; output space           | output character
71          ld  (hl), c     ; output character       | output space
72          ld  (hl), d     ; output space           | output character
B9          cp  c           ; set zero flag 1st time | clear 2nd time
20 06       jr  nz, end     ; skip to end
77          ld  (hl), a     ; output character
73          ld  (hl), e     ; output newline
4A          ld  c, d        ; put space in c
57          ld  d, a        ; put character in d
28 FB       jr  z, loop     ; loop to 2nd time
end:
73          ld  (hl), e     ; output newline
77          ld  (hl), a     ; output character * 4
77          ld  (hl), a
77          ld  (hl), a
77          ld  (hl), a
76          halt            ; or C9 ret

6

LOLCODE, 202 170 bytes

I HAS A c
GIMMEH c
VISIBLE"  "AN c AN c AN c AN c AN":) "AN c AN" "AN c AN" "AN c AN":)"AN c AN c AN c AN"  "AN c AN":)"AN c AN" "AN c AN" "AN c AN":)"AN c AN c AN c AN c

In LOLCODE, not much to golf...

This sets the variable c into the input, and creates a giant concatenated string including :) newlines. That's about it.


expected HAI at: I tio.run/nexus/…
eush77

Also, VISIBLE implicitly concatenates, so you can remove SMOOSH tio.run/nexus/lolcode#@@/…
eush77

To your first thing, there are some interpreters that don't require HAI or KTHXBYE, e.g. REPL.it. To your second thing, thank you!
OldBunny2800

5

Sed, 40 characters

s/./  &&&&\
 & & &\
&&&  &\
& & &\
&&&&/

Almost cheating as the challenge description contained it almost literally.

Sample run:

bash-4.4$ sed 's/./  &&&&\
 & & &\
&&&  &\
& & &\
&&&&/' <<< 'C'
  CCCC
 C C C
CCC  C
C C C
CCCC

Try it online!



4

V, 27 bytes

4äl2>>Äyvho3pÄÙ3älWx<<3Îd^

Try it online!

Hexdump:

00000000: 34e4 6c32 3e3e c479 7668 6f1b 3370 c4d9  4.l2>>.yvho.3p..
00000010: 33e4 6c57 783c 3c33 ce64 5e              3.lWx<<3.d^

I'm pretty sure you can replace o<esc> with just ï
Kritixi Lithos

4

PHP, 72 bytes

I made this one just for the fun of it, since there's already a better PHP answer.

for($i=0;$i<27;)echo('00'.decbin(64349871))[$i]?$argn:' ',++$i%6?'':'
';

The cube is drawn by getting the binary value of 64349871, concatenated by '00'.
This returns the following:

0011110101011110011010101111

Every 6th character, I'm outputting a newline, resulting in this:

001111
010101
111001
101010
1111

And, instead of displaying 0, it displays a space, which will look like:

  1111
 1 1 1
111  1
1 1 1 
1111

4

Charcoal, 17 16 bytes

SβGH7+↗→³β→G↓↙³β

Try it online! Link is to verbose version of code. Longer than I wanted it to be, because the "cube" is slightly wider than it is tall or deep. Fortunately some of the multidirectional characters work with PolygonHollow, which saves me 3 bytes. Edit: Saved a further byte by using + instead of T↑. Explanation:

Sβ          Input the character
GH7+↗→³β    Draw the left half. 7 becomes ←↙ and + becomes →↓←↑.
→           Move right one character.
G↓↙³β       Draw the right half.

At the time of the challenge, the q variable didn't work in verbose mode, otherwise I could have created this 14-byte version:

GH7+↗→³θ→G↓↙³θ

Try it online!


3

Stacked, 31 bytes

' '\+$'9*<'#.2 tb[6 dpad]map#

Try it online!

Here's a hexdump:

λ xxd try-to-make-a-cube.stk
00000000: 2720 275c 2b24 270f 1539 2a3c 2723 2e32  ' '\+$'..9*<'#.2
00000010: 2074 625b 3620 6470 6164 5d6d 6170 23     tb[6 dpad]map#

This converts a character array to binary, pads each row to length 6, and indexes it according to the string ' ' input +



2

JS (ES6), 64 60 52 bytes

i=>`  ####
 # # #
###  #
# # #
####`.replace(/#/g,i)

Can this be improved:

i=>`  ${y=i+i+i+i}
 # # #
###  #
# # #
${y}`.replace(/#/g,i)

1
y=i+i+i+i is shorter than y=i.repeat(4)
Stephen

2
... and #### is even shorter.
Arnauld

1
Actually the whole thing's shorter without templates: Fiddle
Stephen

1

C (gcc), 90 84 bytes

i;v;f(g){for(i=32;i--;)putchar((v="####*@#@#@#*#@@###*#@#@#@*####@@"[i])&1?g:v-32);}

Try it online! Defines a function f that takes a character g. Too bad encoding the table directly is shorter...

Old version, 90 bytes

(Still trying to golf this one)

Trying to have only a single putchar, but idk. There are unprintables, so here is the hexdump:

λ xxd try-to-make-a-cube.c
00000000: 693b 6a3b 6628 6729 7b63 6861 722a 6b3d  i;j;f(g){char*k=
00000010: 220f 1539 2a3c 223b 666f 7228 693d 303b  "..9*<";for(i=0;
00000020: 693c 353b 7075 7463 6861 7228 3130 292c  i<5;putchar(10),
00000030: 692b 2b29 666f 7228 6a3d 3332 3b6a 3b6a  i++)for(j=32;j;j
00000040: 2f3d 3229 7075 7463 6861 7228 6b5b 695d  /=2)putchar(k[i]
00000050: 266a 3f67 3a33 3229 3b7d                 &j?g:32);}

This encodes the cube into a binary lookup table, where a 1 bit represents the input and a 0 bit represents a space. Try it online!


1

Brain-Flak, 217 bytes

(((((((((((((((((({}))))<([][]()())>)<(([][])[]{}())>)<(([][]){})>)<([])>)<(((()
())[][]{}()()))>)))<((()()()()()){})>)<(((()()()){}){}()[])>)<(((()()())()){}{}[
])>)<(((()()())){}{}[])((()()()()()){})>))))(([]()()()))

Try it online!

Waaaaay too long.


1

Swift - 82 bytes + Foundation (18 bytes)?

var f={"  ####\n # # #\n###  #\n# # #\n####".replacingOccurrences(of:"#",with:$0)}

By default, Xcode-Swift projects have Whole-Module Optimization, so that import Foundation is not required for this simple lambda-like function. However, running it in online environments requires it, which may add 18 bytes.

Check it out!



0

CJam, 23 bytes

"pjFUC"{i2b(;}%rS+ff=N*

I feel like I can still golf this.

"pjFUC" e# String literal:          │ "pjFUC"
{       e# For each:                │ 'p
  i     e#   Get code point:        │ 112
  2b    e#   To binary:             │ [1 1 1 0 0 0 0]
  (;    e#   Delete first:          │ [1 1 0 0 0 0]
}%      e# End                      │ [[1 1 0 0 0 0] [1 0 1 0 1 0] [0 0 0 1 1 0] [0 1 0 1 0 1] [0 0 0 0 1 1]]
r       e# Read token:              │ [[1 1 0 0 0 0] [1 0 1 0 1 0] [0 0 0 1 1 0] [0 1 0 1 0 1] [0 0 0 0 1 1]] "&"
S       e# Push space:              │ [[1 1 0 0 0 0] [1 0 1 0 1 0] [0 0 0 1 1 0] [0 1 0 1 0 1] [0 0 0 0 1 1]] "&" " "
+       e# Concatenate:             │ [[1 1 0 0 0 0] [1 0 1 0 1 0] [0 0 0 1 1 0] [0 1 0 1 0 1] [0 0 0 0 1 1]] "& "
ff=     e# Vectorized array lookup: │ ["  &&&&" " & & &" "&&&  &" "& & & " "&&&&  "]
N*      e# Join with newlines       │ "  &&&&
        e#                          │   & & &
        e#                          │  &&&  &
        e#                          │  & & & 
        e#                          │  &&&&  "
e# Implicit output

0

dc, 70 bytes

Encodes the sequence rather directly, with minor optimization:

8224PdPdPdPdP10Pd8192+ddPPP10PdPdPdP8224PdP10Pd256*32+ddPPP10PdPdPdPdP

Try it online!


Taken to a (not very golfy) extreme, 145 bytes:

27065671941896667324298575455432398417474802390765222440949482848513*56759961956005660143530475805610581704254588701249011343446231795984498688+P

Try it online!

This computes A*x+B, where A encodes the positions of the input character and B encodes all the rest:

A = 2560 + 2561 + 2562 + 2563 + 2565 + 2567 + 2569 + 25611 + 25614 + 25615 + 25616 + 25618 + 25620 + 25622 + 25625 + 25626 + 25627 + 25628

B = 10×2564 + 32×2566 + 32×2568 + 10×25610 + 32×25612 + 32×25613 + 10×25617 + 32×25619 + 32×25621 + 32×25623 + 10×25624 + 32×25629 + 32×25630

P command prints the resulting number as a byte stream.



0

Windows batch, 79 bytes

@echo   %1%1%1%1
@echo  %1 %1 %1
@echo %1%1%1  %1
@echo %1 %1 %1
@echo %1%1%1%1

Special char. safe, 97 bytes:

@echo   ^%1^%1^%1^%1
@echo  ^%1 ^%1 ^%1
@echo ^%1^%1^%1  ^%1
@echo ^%1 ^%1 ^%1
@echo ^%1^%1^%1^%1

Can you use line feeds i.e. .. %1%1%1%1\n %1 %1 %1...
TheLethalCoder

Line feeds are not supported in batch
stevefestl

I couldn't remember if they was or not and wasn't in a position to test :)
TheLethalCoder

Sorry, I'm confused, can you repeat?
stevefestl

I couldn't remember if you could use them or not and I couldn't test at the time I commented so I left the comment so you would still have the idea
TheLethalCoder

0

Tcl, 60 bytes

proc c x {regsub . $x "  &&&&\n & & &\n&&&  &\n& & &\n&&&&"}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.