Build ASCII Podiums
$begingroup$
In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.
The podiums are presented below:
@---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |
This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3
wide.
For example, given the input ["Tom", "Ann", "Sue"]
representing first-, second-, and third-place respectively, output the following podiums:
Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |
However, if we have Anne
instead of Ann
, we'll need to go up to the next size, 5
, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne
is to the left of center, but you can choose which side to align to.
Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |
Let's go for some longer names. How about ["William", "Brad", "Eugene"]
:
William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |
Here we can see that Brad
has a lot of whitespace, Eugene
less so, and William
fits just right.
For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]
:
A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |
Finally, we have the smallest possible input, something like ["A", "B", "C"]
:
A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as a name). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
$endgroup$
add a comment |
$begingroup$
In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.
The podiums are presented below:
@---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |
This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3
wide.
For example, given the input ["Tom", "Ann", "Sue"]
representing first-, second-, and third-place respectively, output the following podiums:
Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |
However, if we have Anne
instead of Ann
, we'll need to go up to the next size, 5
, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne
is to the left of center, but you can choose which side to align to.
Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |
Let's go for some longer names. How about ["William", "Brad", "Eugene"]
:
William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |
Here we can see that Brad
has a lot of whitespace, Eugene
less so, and William
fits just right.
For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]
:
A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |
Finally, we have the smallest possible input, something like ["A", "B", "C"]
:
A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as a name). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
$endgroup$
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago
add a comment |
$begingroup$
In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.
The podiums are presented below:
@---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |
This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3
wide.
For example, given the input ["Tom", "Ann", "Sue"]
representing first-, second-, and third-place respectively, output the following podiums:
Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |
However, if we have Anne
instead of Ann
, we'll need to go up to the next size, 5
, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne
is to the left of center, but you can choose which side to align to.
Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |
Let's go for some longer names. How about ["William", "Brad", "Eugene"]
:
William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |
Here we can see that Brad
has a lot of whitespace, Eugene
less so, and William
fits just right.
For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]
:
A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |
Finally, we have the smallest possible input, something like ["A", "B", "C"]
:
A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as a name). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
$endgroup$
In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.
The podiums are presented below:
@---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |
This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3
wide.
For example, given the input ["Tom", "Ann", "Sue"]
representing first-, second-, and third-place respectively, output the following podiums:
Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |
However, if we have Anne
instead of Ann
, we'll need to go up to the next size, 5
, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne
is to the left of center, but you can choose which side to align to.
Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |
Let's go for some longer names. How about ["William", "Brad", "Eugene"]
:
William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |
Here we can see that Brad
has a lot of whitespace, Eugene
less so, and William
fits just right.
For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]
:
A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |
Finally, we have the smallest possible input, something like ["A", "B", "C"]
:
A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as a name). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
code-golf ascii-art
edited 9 hours ago
AdmBorkBork
asked 11 hours ago
AdmBorkBorkAdmBorkBork
27.2k466234
27.2k466234
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago
add a comment |
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
JavaScript (ES8), 196 bytes
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)
Try it online!
$endgroup$
add a comment |
$begingroup$
Canvas, 45 bytes
r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵
Try it here!
Explanation:
r Center the input, preferring left. Converts to an ASCII-art object
which pads everything with spaces. This is the bulk of the magic.
251⁰{ .... } for each number in [2, 5, 1]:
|* repeat "|" vertically that many times
@;∔ prepend an "@" - a vertical bar for later
; swap top 2 stack items - put the centered art on top
J push the 1st line of it (removing it from the art)
└ order the stack to [remaining, "@¶|¶|..", currentLine]
l get the length of the current line
2M max of that and 2
2% that % 2
±├ (-that) + 2
×× prepend (-max(len,2)%2) + 2 spaces
l get the length of the new string
⇵╷ ceil(len / 2) -1
-× repeat "-" that many times - half of the podiums top
└ order stack to [art, currLine, "@¶|¶|..", "----"]
+ append the dashes to the vertical bar = "@-----¶|¶|.."
-α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
k remove the last line of that to make up for the middles shortness
+ and append that horizontally - half of the podium without the name
│ palindromize the podium
∔ and prepend the name
⇵ reverse vertically so the outputs could be aligned to the bottom
; and get the rest of the centered input on top
Finally,
┐ remove the useless now-empty input
++ join the 3 podium parts together
⇵ and undo the reversing
Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
$endgroup$
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
add a comment |
$begingroup$
Groovy, 187, 176 bytes
f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}
Try it online!
Defines a closure f
which can be called via:
f(['tom','ann','sue'])
prints to std out.
Explanation:
Unobfuscating the code, we have:
f={n->
m=n*.size().max()|1
h=' '*(m/2)
a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
println(it.sum{a[it]})
}
}
f={n->
- define closure f with one in-paramn
m=n*.size().max()|1
- find max name len, binary-or to odd number
h=' '*(m/2)
- h will contain floor(m/2) spaces, used later
a=...
- creates an encoding list with elements:
- indexes 0,1,2 - names, centered to max len
- index 3 - m+2 spaces
- index 4 -
@---@
pattern, padded to len - index 5 -
| @ |
pattern, padded to len - index 6 -
| | |
pattern, padded to len
[[3,0],...].any{...}
- use indicies into the encoding list to build and print the result
println(it.sum{a[it]})
- use the fact that string + string works in groovy and call sum on the list of indicies- note in the answer the variable
a
has been inlined,nelines removed etc.
$endgroup$
add a comment |
$begingroup$
Charcoal, 63 bytes
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι⟧
Output the text with enough left padding to centre it.
≔⁻⁷ⅉι
Get the height of the podium.
P↓ι@ηP↓ιP↓@@¹ηP↓ι@
Draw the podium.
Alternative approach, also 63 bytes:
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι
Output the text with enough left padding to centre it.
⪫@-@×-η⟧
Also output the top of the podium by inserting -
s between the characters of the string @-@
to reach the correct width.
E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Print the remainder of the podium by spacing the |
s appropriately, except that the middle character is a @
on the first row.
$endgroup$
add a comment |
$begingroup$
Clean, 209 bytes
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k[' '..]]\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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/3.0/"u003ecc by-sa 3.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%2f180187%2fbuild-ascii-podiums%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (ES8), 196 bytes
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES8), 196 bytes
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES8), 196 bytes
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)
Try it online!
$endgroup$
JavaScript (ES8), 196 bytes
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)
Try it online!
edited 9 hours ago
answered 9 hours ago
ArnauldArnauld
76.4k693321
76.4k693321
add a comment |
add a comment |
$begingroup$
Canvas, 45 bytes
r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵
Try it here!
Explanation:
r Center the input, preferring left. Converts to an ASCII-art object
which pads everything with spaces. This is the bulk of the magic.
251⁰{ .... } for each number in [2, 5, 1]:
|* repeat "|" vertically that many times
@;∔ prepend an "@" - a vertical bar for later
; swap top 2 stack items - put the centered art on top
J push the 1st line of it (removing it from the art)
└ order the stack to [remaining, "@¶|¶|..", currentLine]
l get the length of the current line
2M max of that and 2
2% that % 2
±├ (-that) + 2
×× prepend (-max(len,2)%2) + 2 spaces
l get the length of the new string
⇵╷ ceil(len / 2) -1
-× repeat "-" that many times - half of the podiums top
└ order stack to [art, currLine, "@¶|¶|..", "----"]
+ append the dashes to the vertical bar = "@-----¶|¶|.."
-α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
k remove the last line of that to make up for the middles shortness
+ and append that horizontally - half of the podium without the name
│ palindromize the podium
∔ and prepend the name
⇵ reverse vertically so the outputs could be aligned to the bottom
; and get the rest of the centered input on top
Finally,
┐ remove the useless now-empty input
++ join the 3 podium parts together
⇵ and undo the reversing
Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
$endgroup$
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
add a comment |
$begingroup$
Canvas, 45 bytes
r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵
Try it here!
Explanation:
r Center the input, preferring left. Converts to an ASCII-art object
which pads everything with spaces. This is the bulk of the magic.
251⁰{ .... } for each number in [2, 5, 1]:
|* repeat "|" vertically that many times
@;∔ prepend an "@" - a vertical bar for later
; swap top 2 stack items - put the centered art on top
J push the 1st line of it (removing it from the art)
└ order the stack to [remaining, "@¶|¶|..", currentLine]
l get the length of the current line
2M max of that and 2
2% that % 2
±├ (-that) + 2
×× prepend (-max(len,2)%2) + 2 spaces
l get the length of the new string
⇵╷ ceil(len / 2) -1
-× repeat "-" that many times - half of the podiums top
└ order stack to [art, currLine, "@¶|¶|..", "----"]
+ append the dashes to the vertical bar = "@-----¶|¶|.."
-α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
k remove the last line of that to make up for the middles shortness
+ and append that horizontally - half of the podium without the name
│ palindromize the podium
∔ and prepend the name
⇵ reverse vertically so the outputs could be aligned to the bottom
; and get the rest of the centered input on top
Finally,
┐ remove the useless now-empty input
++ join the 3 podium parts together
⇵ and undo the reversing
Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
$endgroup$
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
add a comment |
$begingroup$
Canvas, 45 bytes
r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵
Try it here!
Explanation:
r Center the input, preferring left. Converts to an ASCII-art object
which pads everything with spaces. This is the bulk of the magic.
251⁰{ .... } for each number in [2, 5, 1]:
|* repeat "|" vertically that many times
@;∔ prepend an "@" - a vertical bar for later
; swap top 2 stack items - put the centered art on top
J push the 1st line of it (removing it from the art)
└ order the stack to [remaining, "@¶|¶|..", currentLine]
l get the length of the current line
2M max of that and 2
2% that % 2
±├ (-that) + 2
×× prepend (-max(len,2)%2) + 2 spaces
l get the length of the new string
⇵╷ ceil(len / 2) -1
-× repeat "-" that many times - half of the podiums top
└ order stack to [art, currLine, "@¶|¶|..", "----"]
+ append the dashes to the vertical bar = "@-----¶|¶|.."
-α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
k remove the last line of that to make up for the middles shortness
+ and append that horizontally - half of the podium without the name
│ palindromize the podium
∔ and prepend the name
⇵ reverse vertically so the outputs could be aligned to the bottom
; and get the rest of the centered input on top
Finally,
┐ remove the useless now-empty input
++ join the 3 podium parts together
⇵ and undo the reversing
Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
$endgroup$
Canvas, 45 bytes
r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵
Try it here!
Explanation:
r Center the input, preferring left. Converts to an ASCII-art object
which pads everything with spaces. This is the bulk of the magic.
251⁰{ .... } for each number in [2, 5, 1]:
|* repeat "|" vertically that many times
@;∔ prepend an "@" - a vertical bar for later
; swap top 2 stack items - put the centered art on top
J push the 1st line of it (removing it from the art)
└ order the stack to [remaining, "@¶|¶|..", currentLine]
l get the length of the current line
2M max of that and 2
2% that % 2
±├ (-that) + 2
×× prepend (-max(len,2)%2) + 2 spaces
l get the length of the new string
⇵╷ ceil(len / 2) -1
-× repeat "-" that many times - half of the podiums top
└ order stack to [art, currLine, "@¶|¶|..", "----"]
+ append the dashes to the vertical bar = "@-----¶|¶|.."
-α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
k remove the last line of that to make up for the middles shortness
+ and append that horizontally - half of the podium without the name
│ palindromize the podium
∔ and prepend the name
⇵ reverse vertically so the outputs could be aligned to the bottom
; and get the rest of the centered input on top
Finally,
┐ remove the useless now-empty input
++ join the 3 podium parts together
⇵ and undo the reversing
Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
edited 5 hours ago
answered 10 hours ago
dzaimadzaima
15.1k21856
15.1k21856
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
add a comment |
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
Umm...any chance of an explanation?
$endgroup$
– Matias Bjarland
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
$begingroup$
@MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
$endgroup$
– dzaima
5 hours ago
add a comment |
$begingroup$
Groovy, 187, 176 bytes
f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}
Try it online!
Defines a closure f
which can be called via:
f(['tom','ann','sue'])
prints to std out.
Explanation:
Unobfuscating the code, we have:
f={n->
m=n*.size().max()|1
h=' '*(m/2)
a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
println(it.sum{a[it]})
}
}
f={n->
- define closure f with one in-paramn
m=n*.size().max()|1
- find max name len, binary-or to odd number
h=' '*(m/2)
- h will contain floor(m/2) spaces, used later
a=...
- creates an encoding list with elements:
- indexes 0,1,2 - names, centered to max len
- index 3 - m+2 spaces
- index 4 -
@---@
pattern, padded to len - index 5 -
| @ |
pattern, padded to len - index 6 -
| | |
pattern, padded to len
[[3,0],...].any{...}
- use indicies into the encoding list to build and print the result
println(it.sum{a[it]})
- use the fact that string + string works in groovy and call sum on the list of indicies- note in the answer the variable
a
has been inlined,nelines removed etc.
$endgroup$
add a comment |
$begingroup$
Groovy, 187, 176 bytes
f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}
Try it online!
Defines a closure f
which can be called via:
f(['tom','ann','sue'])
prints to std out.
Explanation:
Unobfuscating the code, we have:
f={n->
m=n*.size().max()|1
h=' '*(m/2)
a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
println(it.sum{a[it]})
}
}
f={n->
- define closure f with one in-paramn
m=n*.size().max()|1
- find max name len, binary-or to odd number
h=' '*(m/2)
- h will contain floor(m/2) spaces, used later
a=...
- creates an encoding list with elements:
- indexes 0,1,2 - names, centered to max len
- index 3 - m+2 spaces
- index 4 -
@---@
pattern, padded to len - index 5 -
| @ |
pattern, padded to len - index 6 -
| | |
pattern, padded to len
[[3,0],...].any{...}
- use indicies into the encoding list to build and print the result
println(it.sum{a[it]})
- use the fact that string + string works in groovy and call sum on the list of indicies- note in the answer the variable
a
has been inlined,nelines removed etc.
$endgroup$
add a comment |
$begingroup$
Groovy, 187, 176 bytes
f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}
Try it online!
Defines a closure f
which can be called via:
f(['tom','ann','sue'])
prints to std out.
Explanation:
Unobfuscating the code, we have:
f={n->
m=n*.size().max()|1
h=' '*(m/2)
a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
println(it.sum{a[it]})
}
}
f={n->
- define closure f with one in-paramn
m=n*.size().max()|1
- find max name len, binary-or to odd number
h=' '*(m/2)
- h will contain floor(m/2) spaces, used later
a=...
- creates an encoding list with elements:
- indexes 0,1,2 - names, centered to max len
- index 3 - m+2 spaces
- index 4 -
@---@
pattern, padded to len - index 5 -
| @ |
pattern, padded to len - index 6 -
| | |
pattern, padded to len
[[3,0],...].any{...}
- use indicies into the encoding list to build and print the result
println(it.sum{a[it]})
- use the fact that string + string works in groovy and call sum on the list of indicies- note in the answer the variable
a
has been inlined,nelines removed etc.
$endgroup$
Groovy, 187, 176 bytes
f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}
Try it online!
Defines a closure f
which can be called via:
f(['tom','ann','sue'])
prints to std out.
Explanation:
Unobfuscating the code, we have:
f={n->
m=n*.size().max()|1
h=' '*(m/2)
a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
println(it.sum{a[it]})
}
}
f={n->
- define closure f with one in-paramn
m=n*.size().max()|1
- find max name len, binary-or to odd number
h=' '*(m/2)
- h will contain floor(m/2) spaces, used later
a=...
- creates an encoding list with elements:
- indexes 0,1,2 - names, centered to max len
- index 3 - m+2 spaces
- index 4 -
@---@
pattern, padded to len - index 5 -
| @ |
pattern, padded to len - index 6 -
| | |
pattern, padded to len
[[3,0],...].any{...}
- use indicies into the encoding list to build and print the result
println(it.sum{a[it]})
- use the fact that string + string works in groovy and call sum on the list of indicies- note in the answer the variable
a
has been inlined,nelines removed etc.
edited 5 hours ago
answered 6 hours ago
Matias BjarlandMatias Bjarland
34017
34017
add a comment |
add a comment |
$begingroup$
Charcoal, 63 bytes
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι⟧
Output the text with enough left padding to centre it.
≔⁻⁷ⅉι
Get the height of the podium.
P↓ι@ηP↓ιP↓@@¹ηP↓ι@
Draw the podium.
Alternative approach, also 63 bytes:
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι
Output the text with enough left padding to centre it.
⪫@-@×-η⟧
Also output the top of the podium by inserting -
s between the characters of the string @-@
to reach the correct width.
E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Print the remainder of the podium by spacing the |
s appropriately, except that the middle character is a @
on the first row.
$endgroup$
add a comment |
$begingroup$
Charcoal, 63 bytes
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι⟧
Output the text with enough left padding to centre it.
≔⁻⁷ⅉι
Get the height of the podium.
P↓ι@ηP↓ιP↓@@¹ηP↓ι@
Draw the podium.
Alternative approach, also 63 bytes:
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι
Output the text with enough left padding to centre it.
⪫@-@×-η⟧
Also output the top of the podium by inserting -
s between the characters of the string @-@
to reach the correct width.
E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Print the remainder of the podium by spacing the |
s appropriately, except that the middle character is a @
on the first row.
$endgroup$
add a comment |
$begingroup$
Charcoal, 63 bytes
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι⟧
Output the text with enough left padding to centre it.
≔⁻⁷ⅉι
Get the height of the podium.
P↓ι@ηP↓ιP↓@@¹ηP↓ι@
Draw the podium.
Alternative approach, also 63 bytes:
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι
Output the text with enough left padding to centre it.
⪫@-@×-η⟧
Also output the top of the podium by inserting -
s between the characters of the string @-@
to reach the correct width.
E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Print the remainder of the podium by spacing the |
s appropriately, except that the middle character is a @
on the first row.
$endgroup$
Charcoal, 63 bytes
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι⟧
Output the text with enough left padding to centre it.
≔⁻⁷ⅉι
Get the height of the podium.
P↓ι@ηP↓ιP↓@@¹ηP↓ι@
Draw the podium.
Alternative approach, also 63 bytes:
≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Try it online! Link is to verbose version of code. Explanation:
≔÷⌈EθLι²η
Calculate the number of spaces in each half of a podium.
F³«
Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.
J×ι⁺³⊗η⊗﹪⁻¹ι³
Position to the start of the line that will have the text.
⟦◧§θι⁺⊕η⊘⊕L§θι
Output the text with enough left padding to centre it.
⪫@-@×-η⟧
Also output the top of the podium by inserting -
s between the characters of the string @-@
to reach the correct width.
E⁻⁷ⅉ⪫⪫||§|@¬κ× η
Print the remainder of the podium by spacing the |
s appropriately, except that the middle character is a @
on the first row.
answered 4 hours ago
NeilNeil
80.8k744178
80.8k744178
add a comment |
add a comment |
$begingroup$
Clean, 209 bytes
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k[' '..]]\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 209 bytes
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k[' '..]]\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 209 bytes
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k[' '..]]\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])
Try it online!
$endgroup$
Clean, 209 bytes
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k[' '..]]\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])
Try it online!
answered 2 hours ago
ΟurousΟurous
7,12111035
7,12111035
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%2f180187%2fbuild-ascii-podiums%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
$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
3 hours ago