これに基づいて:正方形を作ってみてください!
これを出力する必要があります:
####
# # #
### #
# # #
####
「#」は入力に置き換えられます。
「A」を入力すると、次のようになります
AAAA
A A A
AAA A
A A A
AAAA
「&」を入力すると、次のようになります
&&&&
& & &
&&& &
& & &
&&&&
これに基づいて:正方形を作ってみてください!
これを出力する必要があります:
####
# # #
### #
# # #
####
「#」は入力に置き換えられます。
「A」を入力すると、次のようになります
AAAA
A A A
AAA A
A A A
AAAA
「&」を入力すると、次のようになります
&&&&
& & &
&&& &
& & &
&&&&
回答:
ð‚•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
•nxвΛ•bTRð¹ì‡6ô»
...注文の要件が原因で、あなたの音訳はわずかに文字変換されます。入力を暗黙的に取得01
して1バイトの文字列を生成する方法を考え出すことができれば、これは13/14バイトのソリューションになります。
•nxвΛ•bT𹫇6ô»
またはð«T•nxвΛ•br‡6ô»
同じ長さです。
./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).
Βū&⁵'r⁹‘6n
Explanation:
Βū&⁵'r⁹‘ push " ŗŗŗŗ ŗ ŗ ŗŗŗŗ ŗŗ ŗ ŗ ŗŗŗŗ", where "ŗ" is replaced with input
6n split into lines of length 6
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!
'....' % 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
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)
"OUyj|"®c ¤Åd0S1U +R
Not too bad for a language with no built-in compression (well, except compressing strings of lowercase letters)...
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
ll
can be compressed), but it's 11 bytes longer.
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
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/…
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
4äl2>>Äyvho3pÄÙ3älWx<<3Îd^
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^
o<esc>
with just ï
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
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↓↙³θ
' '\+$'9*<'#.2 tb[6 dpad]map#
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 +
jcsm?d\ zjC"0¨eC"2 6
21 bytes
t::." \"o½MËñ"\!bNw
Also 21 bytes:
:jbct." \" ±¢î
"6Nw
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...
(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!
(((((((((((((((((({}))))<([][]()())>)<(([][])[]{}())>)<(([][]){})>)<([])>)<(((()
())[][]{}()()))>)))<((()()()()()){})>)<(((()()()){}){}()[])>)<(((()()())()){}{}[
])>)<(((()()())){}{}[])((()()()()()){})>))))(([]()()()))
Waaaaay too long.
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.
c->" ####\n # # #\n### #\n# # #\n####".replace('#',c)
String c(char c){return" ####\n # # #\n### #\n# # #\n####".replace('#',c);}
"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
Encodes the sequence rather directly, with minor optimization:
8224PdPdPdPdP10Pd8192+ddPPP10PdPdPdP8224PdP10Pd256*32+ddPPP10PdPdPdPdP
Taken to a (not very golfy) extreme, 145 bytes:
27065671941896667324298575455432398417474802390765222440949482848513*56759961956005660143530475805610581704254588701249011343446231795984498688+P
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.
c=>@" ####
# # #
### #
# # #
####".Replace('#',c);
@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
.. %1%1%1%1\n %1 %1 %1...