ASCII TURNED SHAPEDraw the Heart ShapeAlign a horizontally-aligned, right-angled ASCII shape along a diagonalASCII WaterworksASCII Scores Print out a shape in printable ASCII art based on a specific number of sides provided by the userASCII DandelionsASCII TrianglesReverse columns while preserving shapeShape Identifying ProgramWrite a Shape Simplifier
CircuiTikZ: How to change the node options of labels and annotations?
Drying clothes: windy but cold outside vs warm(ish) inside?
I have just 4 hours a month to security check a cloud based application - How to use my time?
Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?
Listing files that end in ".txt" from directories with the word "SALARIO" in its name without using pipes
Famous statistical wins and horror stories for teaching purposes
Is it acceptable to mark off or comment on someones presentation based on their non-standard English accent?
1 kHz clock over long wire
Why are observers/reference frames able to see themselves moving through time but not through space?
Does 3>&1 imply 4>&3 5>&3 etc.?
Why do we worry about overfitting even if "all models are wrong"?
Is it usual for a US president to make specific comments about a UK Prime Minister's suitability during a general election?
How do I limit the scope of etoolbox environment patching?
Does Amoxicillin (as trihydrate) degrade in stomach acid?
Replacing 2-prong outlets in basement - existing wiring has two hot wires, one neutral?
Interpret numbers very literally
Function to calculate "Nd6 take highest 2, sort descending" probabilities in AnyDice
Why is the Duration of Time spent in the Dayside greater than that of the Night side of the Moon for Chandrayaan-2 Orbiter?
In the top five, I'm odd
Brute-Force algorithm in C++
How to draw a 3D point moving along a helical path?
How should a leader behave when they miss deadlines themselves?
Example satisfying Mangasarian-Fromovitz CQ but not LICQ
What would a life-form be like if it's antimatter-based
ASCII TURNED SHAPE
Draw the Heart ShapeAlign a horizontally-aligned, right-angled ASCII shape along a diagonalASCII WaterworksASCII Scores Print out a shape in printable ASCII art based on a specific number of sides provided by the userASCII DandelionsASCII TrianglesReverse columns while preserving shapeShape Identifying ProgramWrite a Shape Simplifier
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
$begingroup$
How can we depict a turned shape simply and nicely using ascii characters in 3D space?
I suggest this method :
Instead of a circle we use a square rotated by 45° for the cutting section so that we only need '/' and '' characters to draw it.
/
/
/
/
And we use '_' character for the profiles: upper, lower and median.
_________
/
/ ________
/ /
/________/
Isn't it Turning complete? Well, if you agree, write a full program or a function taking an unsigned integer value N , representing a number of steps , producing a 3d shape as described below.
The profile of this turned shape has the form of a stair step curve raising from 0 to N steps and lowering back to 0 where each step is 2 char('/') high and 5 char long ('_').
Maybe some examples describes it more clearly.
For N = 0 you may output nothing but it's not mandatory to handle it.
N = 1
_____
/
/ ____
/ /
/____/
.
N = 2
_____
/
___/_ __
/
/ ____ _____
/ / / / /
/____/ / /_/
/ /
/____/
.
N = 3
_____
/
___/_ __
/
___/_ __
/
/ ____ ____ ______
/ / / / / / / /
/____/ / / / / /_/
/ / / / /
/____/ / /_/
/ /
/____/
Rules :
- Margins are not specified.
- Standard loopholes are forbidden.
- Standard input/output methods.
- Shortest answer in bytes wins.
code-golf ascii-art 3d
$endgroup$
add a comment
|
$begingroup$
How can we depict a turned shape simply and nicely using ascii characters in 3D space?
I suggest this method :
Instead of a circle we use a square rotated by 45° for the cutting section so that we only need '/' and '' characters to draw it.
/
/
/
/
And we use '_' character for the profiles: upper, lower and median.
_________
/
/ ________
/ /
/________/
Isn't it Turning complete? Well, if you agree, write a full program or a function taking an unsigned integer value N , representing a number of steps , producing a 3d shape as described below.
The profile of this turned shape has the form of a stair step curve raising from 0 to N steps and lowering back to 0 where each step is 2 char('/') high and 5 char long ('_').
Maybe some examples describes it more clearly.
For N = 0 you may output nothing but it's not mandatory to handle it.
N = 1
_____
/
/ ____
/ /
/____/
.
N = 2
_____
/
___/_ __
/
/ ____ _____
/ / / / /
/____/ / /_/
/ /
/____/
.
N = 3
_____
/
___/_ __
/
___/_ __
/
/ ____ ____ ______
/ / / / / / / /
/____/ / / / / /_/
/ / / / /
/____/ / /_/
/ /
/____/
Rules :
- Margins are not specified.
- Standard loopholes are forbidden.
- Standard input/output methods.
- Shortest answer in bytes wins.
code-golf ascii-art 3d
$endgroup$
3
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37
add a comment
|
$begingroup$
How can we depict a turned shape simply and nicely using ascii characters in 3D space?
I suggest this method :
Instead of a circle we use a square rotated by 45° for the cutting section so that we only need '/' and '' characters to draw it.
/
/
/
/
And we use '_' character for the profiles: upper, lower and median.
_________
/
/ ________
/ /
/________/
Isn't it Turning complete? Well, if you agree, write a full program or a function taking an unsigned integer value N , representing a number of steps , producing a 3d shape as described below.
The profile of this turned shape has the form of a stair step curve raising from 0 to N steps and lowering back to 0 where each step is 2 char('/') high and 5 char long ('_').
Maybe some examples describes it more clearly.
For N = 0 you may output nothing but it's not mandatory to handle it.
N = 1
_____
/
/ ____
/ /
/____/
.
N = 2
_____
/
___/_ __
/
/ ____ _____
/ / / / /
/____/ / /_/
/ /
/____/
.
N = 3
_____
/
___/_ __
/
___/_ __
/
/ ____ ____ ______
/ / / / / / / /
/____/ / / / / /_/
/ / / / /
/____/ / /_/
/ /
/____/
Rules :
- Margins are not specified.
- Standard loopholes are forbidden.
- Standard input/output methods.
- Shortest answer in bytes wins.
code-golf ascii-art 3d
$endgroup$
How can we depict a turned shape simply and nicely using ascii characters in 3D space?
I suggest this method :
Instead of a circle we use a square rotated by 45° for the cutting section so that we only need '/' and '' characters to draw it.
/
/
/
/
And we use '_' character for the profiles: upper, lower and median.
_________
/
/ ________
/ /
/________/
Isn't it Turning complete? Well, if you agree, write a full program or a function taking an unsigned integer value N , representing a number of steps , producing a 3d shape as described below.
The profile of this turned shape has the form of a stair step curve raising from 0 to N steps and lowering back to 0 where each step is 2 char('/') high and 5 char long ('_').
Maybe some examples describes it more clearly.
For N = 0 you may output nothing but it's not mandatory to handle it.
N = 1
_____
/
/ ____
/ /
/____/
.
N = 2
_____
/
___/_ __
/
/ ____ _____
/ / / / /
/____/ / /_/
/ /
/____/
.
N = 3
_____
/
___/_ __
/
___/_ __
/
/ ____ ____ ______
/ / / / / / / /
/____/ / / / / /_/
/ / / / /
/____/ / /_/
/ /
/____/
Rules :
- Margins are not specified.
- Standard loopholes are forbidden.
- Standard input/output methods.
- Shortest answer in bytes wins.
code-golf ascii-art 3d
code-golf ascii-art 3d
edited Oct 15 at 7:05
AZTECCO
asked Oct 15 at 7:00
AZTECCOAZTECCO
8251 silver badge14 bronze badges
8251 silver badge14 bronze badges
3
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37
add a comment
|
3
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37
3
3
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37
add a comment
|
2 Answers
2
active
oldest
votes
$begingroup$
Charcoal, 70 69 bytes
NθFθ«J⊕×⁷⊕ι⁰≔⊗⊕ιι↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ιJ⁻×⁹θ⊗ι⊖ι__↗ι←P←__↖ι←__
Try it online! Link is to verbose version of code. Explanation:
NθFθ«
Input N
and loop that many times.
J⊕×⁷⊕ι⁰
Jump to the (middle) right corner of the front slice.
≔⊗⊕ιι
Get the size of the slice.
↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ι
Draw the front slice.
J⁻×⁹θ⊗ι⊖ι
Jump to the bottom (that we can see) of the back slice.
__↗ι←P←__↖ι←__
Draw the back slice.
$endgroup$
add a comment
|
$begingroup$
JavaScript (ES8), 322 282 278 272 bytes
Builds the output line by line.
f=(n,y=0,Y=(k=y>2*n)?4*n-y:y,S='___/_25__,/\ \25,\/____/14_/,\ 14,\/____/,_____, \____\, / /, \ \,_\, /, \'.split`,`)=>~Y?(y-2*n?''.padEnd(n*5-(Y>>1)*5-3-y%2-k)+S[y?Y?k*2+y%2:4:5]:'/ 03').replace(/d/g,n=>S[+n+6].repeat(Y-(n>2||-k)>>1))+`
`+f(n,y+1):''
Try it online!
How?
For each row $0 le y le 4n$, we define:
$$k=cases
0,&textif $y le 2n$\
1,&textif $y > 2n$
$$
$$Y=cases
y,&textif $k=0$\
4n-y,&textif $k=1$
$$
Each row is first converted into a main pattern. A main pattern may contain digits: they are placeholders for repeated sub-patterns that are expended afterwards.
The middle row (when $y=2n$) is a special case which is processed separately. For all other rows, we compute the main pattern ID $p$ with:
$$p=cases
5,&textif $y=0$\
4,&textif $y neq 0, Y=0$\
2k+(y bmod 2),&textotherwise\
$$
There are no leading spaces for the middle row. For all other rows, the number $s$ of leading spaces is given by:
$$s=5n-5leftlfloorfracY2rightrfloor-3-(ybmod 2)-k$$
There are inner sub-patterns (marked with a digit $le2$) and outer sub-patterns (marked with a digit $>2$), which are repeated $n_1$ and $n_2$ times respectively:
$$n_1=leftlfloorfracY+k2rightrfloor\
n_2=leftlfloorfracY-12rightrfloor$$
The above formulae apply to the middle row as well, but are irrelevant for the first and last rows, which do not have sub-patterns.
Below is what we get for $n=3$:
y Y k | p | s | before .replace() | n1 | n2 | after .replace()
--------+-----+-----+----------------------+----+----+-----------------------------
0 0 0 | 5 | 12 | ............_____ | 0 | -1 | ............_____
1 1 0 | 1 | 11 | .........../ 25 | 0 | 0 | .........../
2 2 0 | 0 | 7 | .......___/_25__ | 1 | 0 | .......___/_ __
3 3 0 | 1 | 6 | ....../ 25 | 1 | 1 | ....../
4 4 0 | 0 | 2 | ..___/_25__ | 2 | 1 | ..___/_ __
5 5 0 | 1 | 1 | ./ 25 | 2 | 2 | ./
6 6 0 | n/a | n/a | / 03 | 3 | 2 | / ____ ____ ______
7 5 1 | 3 | 0 | 14 | 3 | 2 | / / / / / / / /
8 4 1 | 2 | 1 | ./____/14_/ | 2 | 1 | ./____/ / / / / /_/
9 3 1 | 3 | 5 | ..... 14 | 2 | 1 | ..... / / / / /
10 2 1 | 2 | 6 | ....../____/14_/ | 1 | 0 | ....../____/ / /_/
11 1 1 | 3 | 10 | .......... 14 | 1 | 0 | .......... / /
12 0 1 | 4 | 11 | .........../____/ | 0 | -1 | .........../____/
$endgroup$
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f194279%2fascii-turned-shape%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Charcoal, 70 69 bytes
NθFθ«J⊕×⁷⊕ι⁰≔⊗⊕ιι↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ιJ⁻×⁹θ⊗ι⊖ι__↗ι←P←__↖ι←__
Try it online! Link is to verbose version of code. Explanation:
NθFθ«
Input N
and loop that many times.
J⊕×⁷⊕ι⁰
Jump to the (middle) right corner of the front slice.
≔⊗⊕ιι
Get the size of the slice.
↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ι
Draw the front slice.
J⁻×⁹θ⊗ι⊖ι
Jump to the bottom (that we can see) of the back slice.
__↗ι←P←__↖ι←__
Draw the back slice.
$endgroup$
add a comment
|
$begingroup$
Charcoal, 70 69 bytes
NθFθ«J⊕×⁷⊕ι⁰≔⊗⊕ιι↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ιJ⁻×⁹θ⊗ι⊖ι__↗ι←P←__↖ι←__
Try it online! Link is to verbose version of code. Explanation:
NθFθ«
Input N
and loop that many times.
J⊕×⁷⊕ι⁰
Jump to the (middle) right corner of the front slice.
≔⊗⊕ιι
Get the size of the slice.
↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ι
Draw the front slice.
J⁻×⁹θ⊗ι⊖ι
Jump to the bottom (that we can see) of the back slice.
__↗ι←P←__↖ι←__
Draw the back slice.
$endgroup$
add a comment
|
$begingroup$
Charcoal, 70 69 bytes
NθFθ«J⊕×⁷⊕ι⁰≔⊗⊕ιι↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ιJ⁻×⁹θ⊗ι⊖ι__↗ι←P←__↖ι←__
Try it online! Link is to verbose version of code. Explanation:
NθFθ«
Input N
and loop that many times.
J⊕×⁷⊕ι⁰
Jump to the (middle) right corner of the front slice.
≔⊗⊕ιι
Get the size of the slice.
↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ι
Draw the front slice.
J⁻×⁹θ⊗ι⊖ι
Jump to the bottom (that we can see) of the back slice.
__↗ι←P←__↖ι←__
Draw the back slice.
$endgroup$
Charcoal, 70 69 bytes
NθFθ«J⊕×⁷⊕ι⁰≔⊗⊕ιι↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ιJ⁻×⁹θ⊗ι⊖ι__↗ι←P←__↖ι←__
Try it online! Link is to verbose version of code. Explanation:
NθFθ«
Input N
and loop that many times.
J⊕×⁷⊕ι⁰
Jump to the (middle) right corner of the front slice.
≔⊗⊕ιι
Get the size of the slice.
↙ι↑←×⁵_P↖²→↗ι×⁴_↖ι←×⁵_↓P↙²→↘ι
Draw the front slice.
J⁻×⁹θ⊗ι⊖ι
Jump to the bottom (that we can see) of the back slice.
__↗ι←P←__↖ι←__
Draw the back slice.
edited Oct 15 at 12:34
answered Oct 15 at 11:12
NeilNeil
90.7k8 gold badges46 silver badges190 bronze badges
90.7k8 gold badges46 silver badges190 bronze badges
add a comment
|
add a comment
|
$begingroup$
JavaScript (ES8), 322 282 278 272 bytes
Builds the output line by line.
f=(n,y=0,Y=(k=y>2*n)?4*n-y:y,S='___/_25__,/\ \25,\/____/14_/,\ 14,\/____/,_____, \____\, / /, \ \,_\, /, \'.split`,`)=>~Y?(y-2*n?''.padEnd(n*5-(Y>>1)*5-3-y%2-k)+S[y?Y?k*2+y%2:4:5]:'/ 03').replace(/d/g,n=>S[+n+6].repeat(Y-(n>2||-k)>>1))+`
`+f(n,y+1):''
Try it online!
How?
For each row $0 le y le 4n$, we define:
$$k=cases
0,&textif $y le 2n$\
1,&textif $y > 2n$
$$
$$Y=cases
y,&textif $k=0$\
4n-y,&textif $k=1$
$$
Each row is first converted into a main pattern. A main pattern may contain digits: they are placeholders for repeated sub-patterns that are expended afterwards.
The middle row (when $y=2n$) is a special case which is processed separately. For all other rows, we compute the main pattern ID $p$ with:
$$p=cases
5,&textif $y=0$\
4,&textif $y neq 0, Y=0$\
2k+(y bmod 2),&textotherwise\
$$
There are no leading spaces for the middle row. For all other rows, the number $s$ of leading spaces is given by:
$$s=5n-5leftlfloorfracY2rightrfloor-3-(ybmod 2)-k$$
There are inner sub-patterns (marked with a digit $le2$) and outer sub-patterns (marked with a digit $>2$), which are repeated $n_1$ and $n_2$ times respectively:
$$n_1=leftlfloorfracY+k2rightrfloor\
n_2=leftlfloorfracY-12rightrfloor$$
The above formulae apply to the middle row as well, but are irrelevant for the first and last rows, which do not have sub-patterns.
Below is what we get for $n=3$:
y Y k | p | s | before .replace() | n1 | n2 | after .replace()
--------+-----+-----+----------------------+----+----+-----------------------------
0 0 0 | 5 | 12 | ............_____ | 0 | -1 | ............_____
1 1 0 | 1 | 11 | .........../ 25 | 0 | 0 | .........../
2 2 0 | 0 | 7 | .......___/_25__ | 1 | 0 | .......___/_ __
3 3 0 | 1 | 6 | ....../ 25 | 1 | 1 | ....../
4 4 0 | 0 | 2 | ..___/_25__ | 2 | 1 | ..___/_ __
5 5 0 | 1 | 1 | ./ 25 | 2 | 2 | ./
6 6 0 | n/a | n/a | / 03 | 3 | 2 | / ____ ____ ______
7 5 1 | 3 | 0 | 14 | 3 | 2 | / / / / / / / /
8 4 1 | 2 | 1 | ./____/14_/ | 2 | 1 | ./____/ / / / / /_/
9 3 1 | 3 | 5 | ..... 14 | 2 | 1 | ..... / / / / /
10 2 1 | 2 | 6 | ....../____/14_/ | 1 | 0 | ....../____/ / /_/
11 1 1 | 3 | 10 | .......... 14 | 1 | 0 | .......... / /
12 0 1 | 4 | 11 | .........../____/ | 0 | -1 | .........../____/
$endgroup$
add a comment
|
$begingroup$
JavaScript (ES8), 322 282 278 272 bytes
Builds the output line by line.
f=(n,y=0,Y=(k=y>2*n)?4*n-y:y,S='___/_25__,/\ \25,\/____/14_/,\ 14,\/____/,_____, \____\, / /, \ \,_\, /, \'.split`,`)=>~Y?(y-2*n?''.padEnd(n*5-(Y>>1)*5-3-y%2-k)+S[y?Y?k*2+y%2:4:5]:'/ 03').replace(/d/g,n=>S[+n+6].repeat(Y-(n>2||-k)>>1))+`
`+f(n,y+1):''
Try it online!
How?
For each row $0 le y le 4n$, we define:
$$k=cases
0,&textif $y le 2n$\
1,&textif $y > 2n$
$$
$$Y=cases
y,&textif $k=0$\
4n-y,&textif $k=1$
$$
Each row is first converted into a main pattern. A main pattern may contain digits: they are placeholders for repeated sub-patterns that are expended afterwards.
The middle row (when $y=2n$) is a special case which is processed separately. For all other rows, we compute the main pattern ID $p$ with:
$$p=cases
5,&textif $y=0$\
4,&textif $y neq 0, Y=0$\
2k+(y bmod 2),&textotherwise\
$$
There are no leading spaces for the middle row. For all other rows, the number $s$ of leading spaces is given by:
$$s=5n-5leftlfloorfracY2rightrfloor-3-(ybmod 2)-k$$
There are inner sub-patterns (marked with a digit $le2$) and outer sub-patterns (marked with a digit $>2$), which are repeated $n_1$ and $n_2$ times respectively:
$$n_1=leftlfloorfracY+k2rightrfloor\
n_2=leftlfloorfracY-12rightrfloor$$
The above formulae apply to the middle row as well, but are irrelevant for the first and last rows, which do not have sub-patterns.
Below is what we get for $n=3$:
y Y k | p | s | before .replace() | n1 | n2 | after .replace()
--------+-----+-----+----------------------+----+----+-----------------------------
0 0 0 | 5 | 12 | ............_____ | 0 | -1 | ............_____
1 1 0 | 1 | 11 | .........../ 25 | 0 | 0 | .........../
2 2 0 | 0 | 7 | .......___/_25__ | 1 | 0 | .......___/_ __
3 3 0 | 1 | 6 | ....../ 25 | 1 | 1 | ....../
4 4 0 | 0 | 2 | ..___/_25__ | 2 | 1 | ..___/_ __
5 5 0 | 1 | 1 | ./ 25 | 2 | 2 | ./
6 6 0 | n/a | n/a | / 03 | 3 | 2 | / ____ ____ ______
7 5 1 | 3 | 0 | 14 | 3 | 2 | / / / / / / / /
8 4 1 | 2 | 1 | ./____/14_/ | 2 | 1 | ./____/ / / / / /_/
9 3 1 | 3 | 5 | ..... 14 | 2 | 1 | ..... / / / / /
10 2 1 | 2 | 6 | ....../____/14_/ | 1 | 0 | ....../____/ / /_/
11 1 1 | 3 | 10 | .......... 14 | 1 | 0 | .......... / /
12 0 1 | 4 | 11 | .........../____/ | 0 | -1 | .........../____/
$endgroup$
add a comment
|
$begingroup$
JavaScript (ES8), 322 282 278 272 bytes
Builds the output line by line.
f=(n,y=0,Y=(k=y>2*n)?4*n-y:y,S='___/_25__,/\ \25,\/____/14_/,\ 14,\/____/,_____, \____\, / /, \ \,_\, /, \'.split`,`)=>~Y?(y-2*n?''.padEnd(n*5-(Y>>1)*5-3-y%2-k)+S[y?Y?k*2+y%2:4:5]:'/ 03').replace(/d/g,n=>S[+n+6].repeat(Y-(n>2||-k)>>1))+`
`+f(n,y+1):''
Try it online!
How?
For each row $0 le y le 4n$, we define:
$$k=cases
0,&textif $y le 2n$\
1,&textif $y > 2n$
$$
$$Y=cases
y,&textif $k=0$\
4n-y,&textif $k=1$
$$
Each row is first converted into a main pattern. A main pattern may contain digits: they are placeholders for repeated sub-patterns that are expended afterwards.
The middle row (when $y=2n$) is a special case which is processed separately. For all other rows, we compute the main pattern ID $p$ with:
$$p=cases
5,&textif $y=0$\
4,&textif $y neq 0, Y=0$\
2k+(y bmod 2),&textotherwise\
$$
There are no leading spaces for the middle row. For all other rows, the number $s$ of leading spaces is given by:
$$s=5n-5leftlfloorfracY2rightrfloor-3-(ybmod 2)-k$$
There are inner sub-patterns (marked with a digit $le2$) and outer sub-patterns (marked with a digit $>2$), which are repeated $n_1$ and $n_2$ times respectively:
$$n_1=leftlfloorfracY+k2rightrfloor\
n_2=leftlfloorfracY-12rightrfloor$$
The above formulae apply to the middle row as well, but are irrelevant for the first and last rows, which do not have sub-patterns.
Below is what we get for $n=3$:
y Y k | p | s | before .replace() | n1 | n2 | after .replace()
--------+-----+-----+----------------------+----+----+-----------------------------
0 0 0 | 5 | 12 | ............_____ | 0 | -1 | ............_____
1 1 0 | 1 | 11 | .........../ 25 | 0 | 0 | .........../
2 2 0 | 0 | 7 | .......___/_25__ | 1 | 0 | .......___/_ __
3 3 0 | 1 | 6 | ....../ 25 | 1 | 1 | ....../
4 4 0 | 0 | 2 | ..___/_25__ | 2 | 1 | ..___/_ __
5 5 0 | 1 | 1 | ./ 25 | 2 | 2 | ./
6 6 0 | n/a | n/a | / 03 | 3 | 2 | / ____ ____ ______
7 5 1 | 3 | 0 | 14 | 3 | 2 | / / / / / / / /
8 4 1 | 2 | 1 | ./____/14_/ | 2 | 1 | ./____/ / / / / /_/
9 3 1 | 3 | 5 | ..... 14 | 2 | 1 | ..... / / / / /
10 2 1 | 2 | 6 | ....../____/14_/ | 1 | 0 | ....../____/ / /_/
11 1 1 | 3 | 10 | .......... 14 | 1 | 0 | .......... / /
12 0 1 | 4 | 11 | .........../____/ | 0 | -1 | .........../____/
$endgroup$
JavaScript (ES8), 322 282 278 272 bytes
Builds the output line by line.
f=(n,y=0,Y=(k=y>2*n)?4*n-y:y,S='___/_25__,/\ \25,\/____/14_/,\ 14,\/____/,_____, \____\, / /, \ \,_\, /, \'.split`,`)=>~Y?(y-2*n?''.padEnd(n*5-(Y>>1)*5-3-y%2-k)+S[y?Y?k*2+y%2:4:5]:'/ 03').replace(/d/g,n=>S[+n+6].repeat(Y-(n>2||-k)>>1))+`
`+f(n,y+1):''
Try it online!
How?
For each row $0 le y le 4n$, we define:
$$k=cases
0,&textif $y le 2n$\
1,&textif $y > 2n$
$$
$$Y=cases
y,&textif $k=0$\
4n-y,&textif $k=1$
$$
Each row is first converted into a main pattern. A main pattern may contain digits: they are placeholders for repeated sub-patterns that are expended afterwards.
The middle row (when $y=2n$) is a special case which is processed separately. For all other rows, we compute the main pattern ID $p$ with:
$$p=cases
5,&textif $y=0$\
4,&textif $y neq 0, Y=0$\
2k+(y bmod 2),&textotherwise\
$$
There are no leading spaces for the middle row. For all other rows, the number $s$ of leading spaces is given by:
$$s=5n-5leftlfloorfracY2rightrfloor-3-(ybmod 2)-k$$
There are inner sub-patterns (marked with a digit $le2$) and outer sub-patterns (marked with a digit $>2$), which are repeated $n_1$ and $n_2$ times respectively:
$$n_1=leftlfloorfracY+k2rightrfloor\
n_2=leftlfloorfracY-12rightrfloor$$
The above formulae apply to the middle row as well, but are irrelevant for the first and last rows, which do not have sub-patterns.
Below is what we get for $n=3$:
y Y k | p | s | before .replace() | n1 | n2 | after .replace()
--------+-----+-----+----------------------+----+----+-----------------------------
0 0 0 | 5 | 12 | ............_____ | 0 | -1 | ............_____
1 1 0 | 1 | 11 | .........../ 25 | 0 | 0 | .........../
2 2 0 | 0 | 7 | .......___/_25__ | 1 | 0 | .......___/_ __
3 3 0 | 1 | 6 | ....../ 25 | 1 | 1 | ....../
4 4 0 | 0 | 2 | ..___/_25__ | 2 | 1 | ..___/_ __
5 5 0 | 1 | 1 | ./ 25 | 2 | 2 | ./
6 6 0 | n/a | n/a | / 03 | 3 | 2 | / ____ ____ ______
7 5 1 | 3 | 0 | 14 | 3 | 2 | / / / / / / / /
8 4 1 | 2 | 1 | ./____/14_/ | 2 | 1 | ./____/ / / / / /_/
9 3 1 | 3 | 5 | ..... 14 | 2 | 1 | ..... / / / / /
10 2 1 | 2 | 6 | ....../____/14_/ | 1 | 0 | ....../____/ / /_/
11 1 1 | 3 | 10 | .......... 14 | 1 | 0 | .......... / /
12 0 1 | 4 | 11 | .........../____/ | 0 | -1 | .........../____/
edited Oct 16 at 14:32
answered Oct 15 at 13:09
ArnauldArnauld
96.7k7 gold badges114 silver badges392 bronze badges
96.7k7 gold badges114 silver badges392 bronze badges
add a comment
|
add a comment
|
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f194279%2fascii-turned-shape%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
What if I don't agree ? I may be wrong, but I don't have any task in that case.
$endgroup$
– The random guy
Oct 15 at 7:32
$begingroup$
Sandbox: codegolf.meta.stackexchange.com/a/18149/84844
$endgroup$
– AZTECCO
Oct 15 at 7:37