Borderless table
$begingroup$
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
- X coordinate
- Y coordinate
- String
How?
We know that a Cartesian plane contain 2 axes $(X, Y)$ and 4 quadrants where the signs of the $(X,Y)$ coordinates are $(+,+)$, $(−,+)$, $(−,−)$, and $(+,−)$. For example
Consider the following 3 by 3 matrix as a Cartesian plane
begin{matrix} (-1,1) & (0,1) & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
If we are given in the input something like [[-1,1,L],[0,1,F]]
our matrix will look something similar to
begin{matrix} L & F & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
And the final output LF
In addition to that there are some points we need to follow in order to get the correct output:
- When a X,Y coord is repeated, you will need to concatenate the strings. Example: assume in (-1,1) the string
F
is placed and you need to place the stringa
in the same point. You concatenate both strings resulting inFa
and that is the value that will go in (-1,1). - Your output need to be consistent to the matrix. Example imagine this as your final result:
begin{matrix} Ma & r & ie \ i & s & (1,0) \ cute & (0,-1) & (1,-1) end{matrix}
You must output
Ma rie
i s
cute
Why?
You can view this as a table where the columns are the values of the x-axis and the rows the y-axis.
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma" | "r" | "ie"
Row 2 | "i" | "s" |
Row 3 | "cute" | |
All columns values must have the same length
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma " | "r" | "ie"
Row 2 | "i " | "s" |
Row 3 | "cute" | |
Finnaly we output the result
Ma rie
i s
cute
Test Cases
Input
------------
[[3, 3, "c"]
[4, 1, "un"]
[5, 3, "e"]
[4, 3, "od"]
[4, 2, "lf"]
[1, 2, "go"]
[2, 1, "i"]
[2, 1, "s f"]]
Output
--------------
code
go lf
is f un
Input
--------------
[[0, 0, 's'],
[-1,1, 'M'],
[0, 1, 'r'],
[-1,1, 'a'],
[1, 1, 'i'],
[-1, 0, 'i'],
[1, 1, 'e'],
[-1,- 1, 'c'],
[-1,- 1, 'u'],
[-1, -1, 'te']]
Output.
----------------
Ma rie
i s
cute
Notes
- This is supposed to be code-golf
- You can wrap the coordinates in a single list e.g
[[3, 3], "c"]
- You can take the input in any reasonable format
- You can assume there wont be any number or empty spaces only in the input. e.g. There can be something like
a a
but never1
or" "
or1a
or1 1
code-golf string array-manipulation matrix generation
$endgroup$
|
show 5 more comments
$begingroup$
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
- X coordinate
- Y coordinate
- String
How?
We know that a Cartesian plane contain 2 axes $(X, Y)$ and 4 quadrants where the signs of the $(X,Y)$ coordinates are $(+,+)$, $(−,+)$, $(−,−)$, and $(+,−)$. For example
Consider the following 3 by 3 matrix as a Cartesian plane
begin{matrix} (-1,1) & (0,1) & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
If we are given in the input something like [[-1,1,L],[0,1,F]]
our matrix will look something similar to
begin{matrix} L & F & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
And the final output LF
In addition to that there are some points we need to follow in order to get the correct output:
- When a X,Y coord is repeated, you will need to concatenate the strings. Example: assume in (-1,1) the string
F
is placed and you need to place the stringa
in the same point. You concatenate both strings resulting inFa
and that is the value that will go in (-1,1). - Your output need to be consistent to the matrix. Example imagine this as your final result:
begin{matrix} Ma & r & ie \ i & s & (1,0) \ cute & (0,-1) & (1,-1) end{matrix}
You must output
Ma rie
i s
cute
Why?
You can view this as a table where the columns are the values of the x-axis and the rows the y-axis.
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma" | "r" | "ie"
Row 2 | "i" | "s" |
Row 3 | "cute" | |
All columns values must have the same length
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma " | "r" | "ie"
Row 2 | "i " | "s" |
Row 3 | "cute" | |
Finnaly we output the result
Ma rie
i s
cute
Test Cases
Input
------------
[[3, 3, "c"]
[4, 1, "un"]
[5, 3, "e"]
[4, 3, "od"]
[4, 2, "lf"]
[1, 2, "go"]
[2, 1, "i"]
[2, 1, "s f"]]
Output
--------------
code
go lf
is f un
Input
--------------
[[0, 0, 's'],
[-1,1, 'M'],
[0, 1, 'r'],
[-1,1, 'a'],
[1, 1, 'i'],
[-1, 0, 'i'],
[1, 1, 'e'],
[-1,- 1, 'c'],
[-1,- 1, 'u'],
[-1, -1, 'te']]
Output.
----------------
Ma rie
i s
cute
Notes
- This is supposed to be code-golf
- You can wrap the coordinates in a single list e.g
[[3, 3], "c"]
- You can take the input in any reasonable format
- You can assume there wont be any number or empty spaces only in the input. e.g. There can be something like
a a
but never1
or" "
or1a
or1 1
code-golf string array-manipulation matrix generation
$endgroup$
$begingroup$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
1
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something likea a
but never1
or ` ` or1a
or1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
2
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
Can we take input as a list of named tuples? Something like this:(int a,int b,string c)
?
$endgroup$
– Embodiment of Ignorance
3 hours ago
|
show 5 more comments
$begingroup$
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
- X coordinate
- Y coordinate
- String
How?
We know that a Cartesian plane contain 2 axes $(X, Y)$ and 4 quadrants where the signs of the $(X,Y)$ coordinates are $(+,+)$, $(−,+)$, $(−,−)$, and $(+,−)$. For example
Consider the following 3 by 3 matrix as a Cartesian plane
begin{matrix} (-1,1) & (0,1) & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
If we are given in the input something like [[-1,1,L],[0,1,F]]
our matrix will look something similar to
begin{matrix} L & F & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
And the final output LF
In addition to that there are some points we need to follow in order to get the correct output:
- When a X,Y coord is repeated, you will need to concatenate the strings. Example: assume in (-1,1) the string
F
is placed and you need to place the stringa
in the same point. You concatenate both strings resulting inFa
and that is the value that will go in (-1,1). - Your output need to be consistent to the matrix. Example imagine this as your final result:
begin{matrix} Ma & r & ie \ i & s & (1,0) \ cute & (0,-1) & (1,-1) end{matrix}
You must output
Ma rie
i s
cute
Why?
You can view this as a table where the columns are the values of the x-axis and the rows the y-axis.
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma" | "r" | "ie"
Row 2 | "i" | "s" |
Row 3 | "cute" | |
All columns values must have the same length
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma " | "r" | "ie"
Row 2 | "i " | "s" |
Row 3 | "cute" | |
Finnaly we output the result
Ma rie
i s
cute
Test Cases
Input
------------
[[3, 3, "c"]
[4, 1, "un"]
[5, 3, "e"]
[4, 3, "od"]
[4, 2, "lf"]
[1, 2, "go"]
[2, 1, "i"]
[2, 1, "s f"]]
Output
--------------
code
go lf
is f un
Input
--------------
[[0, 0, 's'],
[-1,1, 'M'],
[0, 1, 'r'],
[-1,1, 'a'],
[1, 1, 'i'],
[-1, 0, 'i'],
[1, 1, 'e'],
[-1,- 1, 'c'],
[-1,- 1, 'u'],
[-1, -1, 'te']]
Output.
----------------
Ma rie
i s
cute
Notes
- This is supposed to be code-golf
- You can wrap the coordinates in a single list e.g
[[3, 3], "c"]
- You can take the input in any reasonable format
- You can assume there wont be any number or empty spaces only in the input. e.g. There can be something like
a a
but never1
or" "
or1a
or1 1
code-golf string array-manipulation matrix generation
$endgroup$
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
- X coordinate
- Y coordinate
- String
How?
We know that a Cartesian plane contain 2 axes $(X, Y)$ and 4 quadrants where the signs of the $(X,Y)$ coordinates are $(+,+)$, $(−,+)$, $(−,−)$, and $(+,−)$. For example
Consider the following 3 by 3 matrix as a Cartesian plane
begin{matrix} (-1,1) & (0,1) & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
If we are given in the input something like [[-1,1,L],[0,1,F]]
our matrix will look something similar to
begin{matrix} L & F & (1,1) \ (-1,0) & (0,0) & (1,0) \ (-1,-1) & (0,-1) & (1,-1) end{matrix}
And the final output LF
In addition to that there are some points we need to follow in order to get the correct output:
- When a X,Y coord is repeated, you will need to concatenate the strings. Example: assume in (-1,1) the string
F
is placed and you need to place the stringa
in the same point. You concatenate both strings resulting inFa
and that is the value that will go in (-1,1). - Your output need to be consistent to the matrix. Example imagine this as your final result:
begin{matrix} Ma & r & ie \ i & s & (1,0) \ cute & (0,-1) & (1,-1) end{matrix}
You must output
Ma rie
i s
cute
Why?
You can view this as a table where the columns are the values of the x-axis and the rows the y-axis.
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma" | "r" | "ie"
Row 2 | "i" | "s" |
Row 3 | "cute" | |
All columns values must have the same length
Column 1 | Column 2 | Column 3
----------------------------------------
Row 1 | "Ma " | "r" | "ie"
Row 2 | "i " | "s" |
Row 3 | "cute" | |
Finnaly we output the result
Ma rie
i s
cute
Test Cases
Input
------------
[[3, 3, "c"]
[4, 1, "un"]
[5, 3, "e"]
[4, 3, "od"]
[4, 2, "lf"]
[1, 2, "go"]
[2, 1, "i"]
[2, 1, "s f"]]
Output
--------------
code
go lf
is f un
Input
--------------
[[0, 0, 's'],
[-1,1, 'M'],
[0, 1, 'r'],
[-1,1, 'a'],
[1, 1, 'i'],
[-1, 0, 'i'],
[1, 1, 'e'],
[-1,- 1, 'c'],
[-1,- 1, 'u'],
[-1, -1, 'te']]
Output.
----------------
Ma rie
i s
cute
Notes
- This is supposed to be code-golf
- You can wrap the coordinates in a single list e.g
[[3, 3], "c"]
- You can take the input in any reasonable format
- You can assume there wont be any number or empty spaces only in the input. e.g. There can be something like
a a
but never1
or" "
or1a
or1 1
code-golf string array-manipulation matrix generation
code-golf string array-manipulation matrix generation
edited 3 hours ago
Adám
29.9k272197
29.9k272197
asked 7 hours ago
Luis felipe De jesus MunozLuis felipe De jesus Munoz
4,36921255
4,36921255
$begingroup$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
1
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something likea a
but never1
or ` ` or1a
or1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
2
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
Can we take input as a list of named tuples? Something like this:(int a,int b,string c)
?
$endgroup$
– Embodiment of Ignorance
3 hours ago
|
show 5 more comments
$begingroup$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
1
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something likea a
but never1
or ` ` or1a
or1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
2
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
Can we take input as a list of named tuples? Something like this:(int a,int b,string c)
?
$endgroup$
– Embodiment of Ignorance
3 hours ago
$begingroup$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
$begingroup$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
1
1
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something like
a a
but never 1
or ` ` or 1a
or 1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something like
a a
but never 1
or ` ` or 1a
or 1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
1
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
2
2
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
1
$begingroup$
Can we take input as a list of named tuples? Something like this:
(int a,int b,string c)
?$endgroup$
– Embodiment of Ignorance
3 hours ago
$begingroup$
Can we take input as a list of named tuples? Something like this:
(int a,int b,string c)
?$endgroup$
– Embodiment of Ignorance
3 hours ago
|
show 5 more comments
7 Answers
7
active
oldest
votes
$begingroup$
JavaScript (ES8), 186 180 179 bytes
Saved 1 byte thanks to @Shaggy
a=>(g=d=>a.some(([x,y,s])=>(w[x+=d]>(l=((r=o[y=d-y]=o[y]||)[x]=[r[x]]+s).length)||(w[x]=l),x|y)<0,w=[o=])?g(-~d):o.map(r=>w.map((w,x)=>(r[x]||'').padEnd(w)).join``).join`
`)``
Try it online!
The JS problem with negative indices
Given an array A
, it's perfectly legal in JS to do something like A[-1] = 5
. However, this will not save the value in the array itself. Instead, it will implicitly coerce this negative index to a string ("-1"
) and set the corresponding property in the surrounding object of the array.
The bad news is that properties are not iterable with methods such as map()
:
a = ;
a[1] = 3;
a[-1] = 5;
a.map((v, i) => console.log(v + ' is stored at index ' + i))
Try it online!
The above code will only display 3 is stored at index 1
.
A possible workaround would be:
a = ;
a[1] = 3;
a[-1] = 5;
Object.keys(a).map(k => console.log(a[k] + ' is stored with key ' + k))
Try it online!
But:
- This is not very golf-friendly.
- The keys are not sorted in numerical order.
What we do here
We definitely want to work with positive values of both $x$ and $y$ in order to avoid the problems described above.
We could do a first pass on the data, looking for the minimum value of $x$ and the minimum value of $y$. But that would be quite lengthy.
Here's what we do instead:
- we start with $d=0$
- we process an iteration where $x$ is replaced with $x+d$ and $y$ is replaced with $d-y$
- if we have either $x<0$ or $y<0$ for any entry, we abort and recursively start another attempt with $d+1$
$endgroup$
$begingroup$
I think you can save a byte by declaringo
withinw
:w=[o=]
.
$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
add a comment |
$begingroup$
Python 2, 188 185 181 bytes
s=sorted;d={};k={}
for x,y,c in input():d[x]=d.get(x,{});k[~y]=d[x][y]=d[x].get(y,'')+c
for y in s(k):print''.join('%*s'%(-max(map(len,d[x].values())),d[x].get(~y,''))for x in s(d))
Try it online!
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 39 bytesSBCS
Anonymous infix lambda taking* lists of coordinates and strings as left and right arguments.
{⊃,/↑¨↓⌽m⊣m[c],←⍵⊣m←(⊃⌈/c←1+⍺-⌊/⍺)⍴⊂''}
Try it online!
{
…}
"dfn"; left (coordinates) and right (strings) arguments are ⍺
and ⍵
:
⊂''
enclosed empty string, so use as fill for an array
(
…)⍴
cyclically reshape into an array of the following dimensions:
⌊/⍺
the lowest value along each axis of the coordinates
⍺-
subtract that from all the coordinates
1+
add that to one (since we want the inclusive range)
c←
store in c
(for coordinates)
⌈/
the highest value along each axis of those
⊃
unpack to use as dimensions
m←
store in m
(for matrix)
⍵⊣
discard that in favour of the strings
m[c],←
append those to m
at the coordinates c
m⊣
discard those in favour of the amended m
⌽
mirror
↓
split into list of lists of strings
↑¨
mix each list of strings into a character matrix, padding with spaces
,/
reduce by horizontal concatenation
⊃
unpack (since reduction reduces rank from 1 to 0)
* If taking a single argument of interwoven coordinates and strings is required, it will be 5 bytes longer.
$endgroup$
add a comment |
$begingroup$
05AB1E, 45 44 bytes
WsàŸãεUõIvyнXQiyθ«]IZsß->ôεíDéθgjí}øRJʒðKĀ}»
Takes the input-coordinates as an inner list.
Try it online or verify all test cases.
Explanation:
Wsà # Get the minimum and maximum of the (implicit) input-list
Ÿ # Create a list in the range [min, max]
ã # Create each possible pair by taking the cartesian product with itself
ε # Map each coordinate to:
U # Pop and store the coordinate in variable `X`
õ # Push an empty string ""
Iv # Loop `y` over the input-items:
yн # Get the coordinates of item `y`
XQi # If it's equal to variable `X`:
yθ # Get the string of item `y`
« # Concat it to the (non-)empty string
] # Close the if-statement, loop, and map
IZsß # Get the maximum and minimum of the input-list
- # Subtract them from each other
> # And increase it by 1
ô # Split the list into parts of this size
ε # Map each part to:
í # Reverse each inner string
Déθg # Get the length of the longest inner string
j # Prepend spaces to each item up to that length
í # And reverse every item back again
# (so the spaces are trailing instead of leading)
}ø # After the map: zip/transpose; swapping rows/columns
R # Reverse the entire list
J # Join each inner list together to a single string
ʒðKĀ} # Remove all strings consisting only of spaces
» # Join the strings by newlines (and output implicitly)
$endgroup$
add a comment |
$begingroup$
Charcoal, 60 bytes
≔Eθ§ι¹η≔Eθ§ι⁰ζF…·⌊ζ⌈ζ«≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε⮌εM⌈EεLκ±Lε
Try it online! Link is to verbose version of code. Explanation:
≔Eθ§ι¹η≔Eθ§ι⁰ζ
Extract the coordinates from the input.
F…·⌊ζ⌈ζ«
Loop over the x-coordinates.
≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε
Loop over the y-coordinates, extracting and concatenating all of the strings at the given coordinates.
⮌ε
Print the strings in reverse order as the y-coordinates are reversed compared to Charcoal's coordinate system.
M⌈EεLκ±Lε
Move to the start of the next column.
$endgroup$
add a comment |
$begingroup$
Perl 5 -p00
-MList::Util=max
, 148 bytes
s/(S+) (S+) (.*)
/$a{$1}=max$a{$1},length($h{$2}{$1}.=$3);''/ge;for$y(sort{$b-$a}keys%h){map{printf"%-$a{$_}s",$h{$y}{$_}}sort{$a-$b}keys%a;say""}
TIO
How
s/(S+) (S+) (.*)
...
/;''/ge;
, substitution flags/g
loop/e
eval, replacement evaluates to empty clearing line input/default variable
$a{$1}=max$a{$1},length($h{$2}{$1}.=$3)
, autovivifies a map %h of map whose first level keysy
second levelx
and concatenate string$3
to the value, get the length and autovivifies a second map %a whose keysx
and value the max of length over the column (x
)
for$y(sort{$b-$a}keys%h){
...;say""}
, for row indices$y
in keys of%h
sorted numerically reverse,say""
at the end to print a newline
map{
...}sort{$a-$b}keys%a
, for column index$_
in keys %a sorted numerically
printf"%-$a{$_}s",$h{$y}{$_}
, print string aligned to the left with column width
$endgroup$
add a comment |
$begingroup$
Clean, 212 206 bytes
import StdEnv,StdLib
? =minList
m=maxList
c=flatten
$a#(x,y,z)=unzip3 a
=flatlines(map c(transpose[[ljustify(m(map length l))k\l<-[reverse[c[s\(u,v,s)<-a|u==i&&v==j]\j<-[?y..m y]]],k<-l]\i<-[?x..m x]]))
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%2f179519%2fborderless-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
JavaScript (ES8), 186 180 179 bytes
Saved 1 byte thanks to @Shaggy
a=>(g=d=>a.some(([x,y,s])=>(w[x+=d]>(l=((r=o[y=d-y]=o[y]||)[x]=[r[x]]+s).length)||(w[x]=l),x|y)<0,w=[o=])?g(-~d):o.map(r=>w.map((w,x)=>(r[x]||'').padEnd(w)).join``).join`
`)``
Try it online!
The JS problem with negative indices
Given an array A
, it's perfectly legal in JS to do something like A[-1] = 5
. However, this will not save the value in the array itself. Instead, it will implicitly coerce this negative index to a string ("-1"
) and set the corresponding property in the surrounding object of the array.
The bad news is that properties are not iterable with methods such as map()
:
a = ;
a[1] = 3;
a[-1] = 5;
a.map((v, i) => console.log(v + ' is stored at index ' + i))
Try it online!
The above code will only display 3 is stored at index 1
.
A possible workaround would be:
a = ;
a[1] = 3;
a[-1] = 5;
Object.keys(a).map(k => console.log(a[k] + ' is stored with key ' + k))
Try it online!
But:
- This is not very golf-friendly.
- The keys are not sorted in numerical order.
What we do here
We definitely want to work with positive values of both $x$ and $y$ in order to avoid the problems described above.
We could do a first pass on the data, looking for the minimum value of $x$ and the minimum value of $y$. But that would be quite lengthy.
Here's what we do instead:
- we start with $d=0$
- we process an iteration where $x$ is replaced with $x+d$ and $y$ is replaced with $d-y$
- if we have either $x<0$ or $y<0$ for any entry, we abort and recursively start another attempt with $d+1$
$endgroup$
$begingroup$
I think you can save a byte by declaringo
withinw
:w=[o=]
.
$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
add a comment |
$begingroup$
JavaScript (ES8), 186 180 179 bytes
Saved 1 byte thanks to @Shaggy
a=>(g=d=>a.some(([x,y,s])=>(w[x+=d]>(l=((r=o[y=d-y]=o[y]||)[x]=[r[x]]+s).length)||(w[x]=l),x|y)<0,w=[o=])?g(-~d):o.map(r=>w.map((w,x)=>(r[x]||'').padEnd(w)).join``).join`
`)``
Try it online!
The JS problem with negative indices
Given an array A
, it's perfectly legal in JS to do something like A[-1] = 5
. However, this will not save the value in the array itself. Instead, it will implicitly coerce this negative index to a string ("-1"
) and set the corresponding property in the surrounding object of the array.
The bad news is that properties are not iterable with methods such as map()
:
a = ;
a[1] = 3;
a[-1] = 5;
a.map((v, i) => console.log(v + ' is stored at index ' + i))
Try it online!
The above code will only display 3 is stored at index 1
.
A possible workaround would be:
a = ;
a[1] = 3;
a[-1] = 5;
Object.keys(a).map(k => console.log(a[k] + ' is stored with key ' + k))
Try it online!
But:
- This is not very golf-friendly.
- The keys are not sorted in numerical order.
What we do here
We definitely want to work with positive values of both $x$ and $y$ in order to avoid the problems described above.
We could do a first pass on the data, looking for the minimum value of $x$ and the minimum value of $y$. But that would be quite lengthy.
Here's what we do instead:
- we start with $d=0$
- we process an iteration where $x$ is replaced with $x+d$ and $y$ is replaced with $d-y$
- if we have either $x<0$ or $y<0$ for any entry, we abort and recursively start another attempt with $d+1$
$endgroup$
$begingroup$
I think you can save a byte by declaringo
withinw
:w=[o=]
.
$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
add a comment |
$begingroup$
JavaScript (ES8), 186 180 179 bytes
Saved 1 byte thanks to @Shaggy
a=>(g=d=>a.some(([x,y,s])=>(w[x+=d]>(l=((r=o[y=d-y]=o[y]||)[x]=[r[x]]+s).length)||(w[x]=l),x|y)<0,w=[o=])?g(-~d):o.map(r=>w.map((w,x)=>(r[x]||'').padEnd(w)).join``).join`
`)``
Try it online!
The JS problem with negative indices
Given an array A
, it's perfectly legal in JS to do something like A[-1] = 5
. However, this will not save the value in the array itself. Instead, it will implicitly coerce this negative index to a string ("-1"
) and set the corresponding property in the surrounding object of the array.
The bad news is that properties are not iterable with methods such as map()
:
a = ;
a[1] = 3;
a[-1] = 5;
a.map((v, i) => console.log(v + ' is stored at index ' + i))
Try it online!
The above code will only display 3 is stored at index 1
.
A possible workaround would be:
a = ;
a[1] = 3;
a[-1] = 5;
Object.keys(a).map(k => console.log(a[k] + ' is stored with key ' + k))
Try it online!
But:
- This is not very golf-friendly.
- The keys are not sorted in numerical order.
What we do here
We definitely want to work with positive values of both $x$ and $y$ in order to avoid the problems described above.
We could do a first pass on the data, looking for the minimum value of $x$ and the minimum value of $y$. But that would be quite lengthy.
Here's what we do instead:
- we start with $d=0$
- we process an iteration where $x$ is replaced with $x+d$ and $y$ is replaced with $d-y$
- if we have either $x<0$ or $y<0$ for any entry, we abort and recursively start another attempt with $d+1$
$endgroup$
JavaScript (ES8), 186 180 179 bytes
Saved 1 byte thanks to @Shaggy
a=>(g=d=>a.some(([x,y,s])=>(w[x+=d]>(l=((r=o[y=d-y]=o[y]||)[x]=[r[x]]+s).length)||(w[x]=l),x|y)<0,w=[o=])?g(-~d):o.map(r=>w.map((w,x)=>(r[x]||'').padEnd(w)).join``).join`
`)``
Try it online!
The JS problem with negative indices
Given an array A
, it's perfectly legal in JS to do something like A[-1] = 5
. However, this will not save the value in the array itself. Instead, it will implicitly coerce this negative index to a string ("-1"
) and set the corresponding property in the surrounding object of the array.
The bad news is that properties are not iterable with methods such as map()
:
a = ;
a[1] = 3;
a[-1] = 5;
a.map((v, i) => console.log(v + ' is stored at index ' + i))
Try it online!
The above code will only display 3 is stored at index 1
.
A possible workaround would be:
a = ;
a[1] = 3;
a[-1] = 5;
Object.keys(a).map(k => console.log(a[k] + ' is stored with key ' + k))
Try it online!
But:
- This is not very golf-friendly.
- The keys are not sorted in numerical order.
What we do here
We definitely want to work with positive values of both $x$ and $y$ in order to avoid the problems described above.
We could do a first pass on the data, looking for the minimum value of $x$ and the minimum value of $y$. But that would be quite lengthy.
Here's what we do instead:
- we start with $d=0$
- we process an iteration where $x$ is replaced with $x+d$ and $y$ is replaced with $d-y$
- if we have either $x<0$ or $y<0$ for any entry, we abort and recursively start another attempt with $d+1$
edited 4 hours ago
answered 5 hours ago
ArnauldArnauld
75.4k691317
75.4k691317
$begingroup$
I think you can save a byte by declaringo
withinw
:w=[o=]
.
$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
add a comment |
$begingroup$
I think you can save a byte by declaringo
withinw
:w=[o=]
.
$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
$begingroup$
I think you can save a byte by declaring
o
within w
: w=[o=]
.$endgroup$
– Shaggy
4 hours ago
$begingroup$
I think you can save a byte by declaring
o
within w
: w=[o=]
.$endgroup$
– Shaggy
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
$begingroup$
@Shaggy I think that's safe indeed. Thanks. :)
$endgroup$
– Arnauld
4 hours ago
add a comment |
$begingroup$
Python 2, 188 185 181 bytes
s=sorted;d={};k={}
for x,y,c in input():d[x]=d.get(x,{});k[~y]=d[x][y]=d[x].get(y,'')+c
for y in s(k):print''.join('%*s'%(-max(map(len,d[x].values())),d[x].get(~y,''))for x in s(d))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 188 185 181 bytes
s=sorted;d={};k={}
for x,y,c in input():d[x]=d.get(x,{});k[~y]=d[x][y]=d[x].get(y,'')+c
for y in s(k):print''.join('%*s'%(-max(map(len,d[x].values())),d[x].get(~y,''))for x in s(d))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 188 185 181 bytes
s=sorted;d={};k={}
for x,y,c in input():d[x]=d.get(x,{});k[~y]=d[x][y]=d[x].get(y,'')+c
for y in s(k):print''.join('%*s'%(-max(map(len,d[x].values())),d[x].get(~y,''))for x in s(d))
Try it online!
$endgroup$
Python 2, 188 185 181 bytes
s=sorted;d={};k={}
for x,y,c in input():d[x]=d.get(x,{});k[~y]=d[x][y]=d[x].get(y,'')+c
for y in s(k):print''.join('%*s'%(-max(map(len,d[x].values())),d[x].get(~y,''))for x in s(d))
Try it online!
edited 6 hours ago
answered 6 hours ago
TFeldTFeld
15k21242
15k21242
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 39 bytesSBCS
Anonymous infix lambda taking* lists of coordinates and strings as left and right arguments.
{⊃,/↑¨↓⌽m⊣m[c],←⍵⊣m←(⊃⌈/c←1+⍺-⌊/⍺)⍴⊂''}
Try it online!
{
…}
"dfn"; left (coordinates) and right (strings) arguments are ⍺
and ⍵
:
⊂''
enclosed empty string, so use as fill for an array
(
…)⍴
cyclically reshape into an array of the following dimensions:
⌊/⍺
the lowest value along each axis of the coordinates
⍺-
subtract that from all the coordinates
1+
add that to one (since we want the inclusive range)
c←
store in c
(for coordinates)
⌈/
the highest value along each axis of those
⊃
unpack to use as dimensions
m←
store in m
(for matrix)
⍵⊣
discard that in favour of the strings
m[c],←
append those to m
at the coordinates c
m⊣
discard those in favour of the amended m
⌽
mirror
↓
split into list of lists of strings
↑¨
mix each list of strings into a character matrix, padding with spaces
,/
reduce by horizontal concatenation
⊃
unpack (since reduction reduces rank from 1 to 0)
* If taking a single argument of interwoven coordinates and strings is required, it will be 5 bytes longer.
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 39 bytesSBCS
Anonymous infix lambda taking* lists of coordinates and strings as left and right arguments.
{⊃,/↑¨↓⌽m⊣m[c],←⍵⊣m←(⊃⌈/c←1+⍺-⌊/⍺)⍴⊂''}
Try it online!
{
…}
"dfn"; left (coordinates) and right (strings) arguments are ⍺
and ⍵
:
⊂''
enclosed empty string, so use as fill for an array
(
…)⍴
cyclically reshape into an array of the following dimensions:
⌊/⍺
the lowest value along each axis of the coordinates
⍺-
subtract that from all the coordinates
1+
add that to one (since we want the inclusive range)
c←
store in c
(for coordinates)
⌈/
the highest value along each axis of those
⊃
unpack to use as dimensions
m←
store in m
(for matrix)
⍵⊣
discard that in favour of the strings
m[c],←
append those to m
at the coordinates c
m⊣
discard those in favour of the amended m
⌽
mirror
↓
split into list of lists of strings
↑¨
mix each list of strings into a character matrix, padding with spaces
,/
reduce by horizontal concatenation
⊃
unpack (since reduction reduces rank from 1 to 0)
* If taking a single argument of interwoven coordinates and strings is required, it will be 5 bytes longer.
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 39 bytesSBCS
Anonymous infix lambda taking* lists of coordinates and strings as left and right arguments.
{⊃,/↑¨↓⌽m⊣m[c],←⍵⊣m←(⊃⌈/c←1+⍺-⌊/⍺)⍴⊂''}
Try it online!
{
…}
"dfn"; left (coordinates) and right (strings) arguments are ⍺
and ⍵
:
⊂''
enclosed empty string, so use as fill for an array
(
…)⍴
cyclically reshape into an array of the following dimensions:
⌊/⍺
the lowest value along each axis of the coordinates
⍺-
subtract that from all the coordinates
1+
add that to one (since we want the inclusive range)
c←
store in c
(for coordinates)
⌈/
the highest value along each axis of those
⊃
unpack to use as dimensions
m←
store in m
(for matrix)
⍵⊣
discard that in favour of the strings
m[c],←
append those to m
at the coordinates c
m⊣
discard those in favour of the amended m
⌽
mirror
↓
split into list of lists of strings
↑¨
mix each list of strings into a character matrix, padding with spaces
,/
reduce by horizontal concatenation
⊃
unpack (since reduction reduces rank from 1 to 0)
* If taking a single argument of interwoven coordinates and strings is required, it will be 5 bytes longer.
$endgroup$
APL (Dyalog Unicode), 39 bytesSBCS
Anonymous infix lambda taking* lists of coordinates and strings as left and right arguments.
{⊃,/↑¨↓⌽m⊣m[c],←⍵⊣m←(⊃⌈/c←1+⍺-⌊/⍺)⍴⊂''}
Try it online!
{
…}
"dfn"; left (coordinates) and right (strings) arguments are ⍺
and ⍵
:
⊂''
enclosed empty string, so use as fill for an array
(
…)⍴
cyclically reshape into an array of the following dimensions:
⌊/⍺
the lowest value along each axis of the coordinates
⍺-
subtract that from all the coordinates
1+
add that to one (since we want the inclusive range)
c←
store in c
(for coordinates)
⌈/
the highest value along each axis of those
⊃
unpack to use as dimensions
m←
store in m
(for matrix)
⍵⊣
discard that in favour of the strings
m[c],←
append those to m
at the coordinates c
m⊣
discard those in favour of the amended m
⌽
mirror
↓
split into list of lists of strings
↑¨
mix each list of strings into a character matrix, padding with spaces
,/
reduce by horizontal concatenation
⊃
unpack (since reduction reduces rank from 1 to 0)
* If taking a single argument of interwoven coordinates and strings is required, it will be 5 bytes longer.
edited 3 hours ago
answered 5 hours ago
AdámAdám
29.9k272197
29.9k272197
add a comment |
add a comment |
$begingroup$
05AB1E, 45 44 bytes
WsàŸãεUõIvyнXQiyθ«]IZsß->ôεíDéθgjí}øRJʒðKĀ}»
Takes the input-coordinates as an inner list.
Try it online or verify all test cases.
Explanation:
Wsà # Get the minimum and maximum of the (implicit) input-list
Ÿ # Create a list in the range [min, max]
ã # Create each possible pair by taking the cartesian product with itself
ε # Map each coordinate to:
U # Pop and store the coordinate in variable `X`
õ # Push an empty string ""
Iv # Loop `y` over the input-items:
yн # Get the coordinates of item `y`
XQi # If it's equal to variable `X`:
yθ # Get the string of item `y`
« # Concat it to the (non-)empty string
] # Close the if-statement, loop, and map
IZsß # Get the maximum and minimum of the input-list
- # Subtract them from each other
> # And increase it by 1
ô # Split the list into parts of this size
ε # Map each part to:
í # Reverse each inner string
Déθg # Get the length of the longest inner string
j # Prepend spaces to each item up to that length
í # And reverse every item back again
# (so the spaces are trailing instead of leading)
}ø # After the map: zip/transpose; swapping rows/columns
R # Reverse the entire list
J # Join each inner list together to a single string
ʒðKĀ} # Remove all strings consisting only of spaces
» # Join the strings by newlines (and output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 45 44 bytes
WsàŸãεUõIvyнXQiyθ«]IZsß->ôεíDéθgjí}øRJʒðKĀ}»
Takes the input-coordinates as an inner list.
Try it online or verify all test cases.
Explanation:
Wsà # Get the minimum and maximum of the (implicit) input-list
Ÿ # Create a list in the range [min, max]
ã # Create each possible pair by taking the cartesian product with itself
ε # Map each coordinate to:
U # Pop and store the coordinate in variable `X`
õ # Push an empty string ""
Iv # Loop `y` over the input-items:
yн # Get the coordinates of item `y`
XQi # If it's equal to variable `X`:
yθ # Get the string of item `y`
« # Concat it to the (non-)empty string
] # Close the if-statement, loop, and map
IZsß # Get the maximum and minimum of the input-list
- # Subtract them from each other
> # And increase it by 1
ô # Split the list into parts of this size
ε # Map each part to:
í # Reverse each inner string
Déθg # Get the length of the longest inner string
j # Prepend spaces to each item up to that length
í # And reverse every item back again
# (so the spaces are trailing instead of leading)
}ø # After the map: zip/transpose; swapping rows/columns
R # Reverse the entire list
J # Join each inner list together to a single string
ʒðKĀ} # Remove all strings consisting only of spaces
» # Join the strings by newlines (and output implicitly)
$endgroup$
add a comment |
$begingroup$
05AB1E, 45 44 bytes
WsàŸãεUõIvyнXQiyθ«]IZsß->ôεíDéθgjí}øRJʒðKĀ}»
Takes the input-coordinates as an inner list.
Try it online or verify all test cases.
Explanation:
Wsà # Get the minimum and maximum of the (implicit) input-list
Ÿ # Create a list in the range [min, max]
ã # Create each possible pair by taking the cartesian product with itself
ε # Map each coordinate to:
U # Pop and store the coordinate in variable `X`
õ # Push an empty string ""
Iv # Loop `y` over the input-items:
yн # Get the coordinates of item `y`
XQi # If it's equal to variable `X`:
yθ # Get the string of item `y`
« # Concat it to the (non-)empty string
] # Close the if-statement, loop, and map
IZsß # Get the maximum and minimum of the input-list
- # Subtract them from each other
> # And increase it by 1
ô # Split the list into parts of this size
ε # Map each part to:
í # Reverse each inner string
Déθg # Get the length of the longest inner string
j # Prepend spaces to each item up to that length
í # And reverse every item back again
# (so the spaces are trailing instead of leading)
}ø # After the map: zip/transpose; swapping rows/columns
R # Reverse the entire list
J # Join each inner list together to a single string
ʒðKĀ} # Remove all strings consisting only of spaces
» # Join the strings by newlines (and output implicitly)
$endgroup$
05AB1E, 45 44 bytes
WsàŸãεUõIvyнXQiyθ«]IZsß->ôεíDéθgjí}øRJʒðKĀ}»
Takes the input-coordinates as an inner list.
Try it online or verify all test cases.
Explanation:
Wsà # Get the minimum and maximum of the (implicit) input-list
Ÿ # Create a list in the range [min, max]
ã # Create each possible pair by taking the cartesian product with itself
ε # Map each coordinate to:
U # Pop and store the coordinate in variable `X`
õ # Push an empty string ""
Iv # Loop `y` over the input-items:
yн # Get the coordinates of item `y`
XQi # If it's equal to variable `X`:
yθ # Get the string of item `y`
« # Concat it to the (non-)empty string
] # Close the if-statement, loop, and map
IZsß # Get the maximum and minimum of the input-list
- # Subtract them from each other
> # And increase it by 1
ô # Split the list into parts of this size
ε # Map each part to:
í # Reverse each inner string
Déθg # Get the length of the longest inner string
j # Prepend spaces to each item up to that length
í # And reverse every item back again
# (so the spaces are trailing instead of leading)
}ø # After the map: zip/transpose; swapping rows/columns
R # Reverse the entire list
J # Join each inner list together to a single string
ʒðKĀ} # Remove all strings consisting only of spaces
» # Join the strings by newlines (and output implicitly)
edited 4 hours ago
answered 4 hours ago
Kevin CruijssenKevin Cruijssen
37.6k556195
37.6k556195
add a comment |
add a comment |
$begingroup$
Charcoal, 60 bytes
≔Eθ§ι¹η≔Eθ§ι⁰ζF…·⌊ζ⌈ζ«≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε⮌εM⌈EεLκ±Lε
Try it online! Link is to verbose version of code. Explanation:
≔Eθ§ι¹η≔Eθ§ι⁰ζ
Extract the coordinates from the input.
F…·⌊ζ⌈ζ«
Loop over the x-coordinates.
≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε
Loop over the y-coordinates, extracting and concatenating all of the strings at the given coordinates.
⮌ε
Print the strings in reverse order as the y-coordinates are reversed compared to Charcoal's coordinate system.
M⌈EεLκ±Lε
Move to the start of the next column.
$endgroup$
add a comment |
$begingroup$
Charcoal, 60 bytes
≔Eθ§ι¹η≔Eθ§ι⁰ζF…·⌊ζ⌈ζ«≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε⮌εM⌈EεLκ±Lε
Try it online! Link is to verbose version of code. Explanation:
≔Eθ§ι¹η≔Eθ§ι⁰ζ
Extract the coordinates from the input.
F…·⌊ζ⌈ζ«
Loop over the x-coordinates.
≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε
Loop over the y-coordinates, extracting and concatenating all of the strings at the given coordinates.
⮌ε
Print the strings in reverse order as the y-coordinates are reversed compared to Charcoal's coordinate system.
M⌈EεLκ±Lε
Move to the start of the next column.
$endgroup$
add a comment |
$begingroup$
Charcoal, 60 bytes
≔Eθ§ι¹η≔Eθ§ι⁰ζF…·⌊ζ⌈ζ«≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε⮌εM⌈EεLκ±Lε
Try it online! Link is to verbose version of code. Explanation:
≔Eθ§ι¹η≔Eθ§ι⁰ζ
Extract the coordinates from the input.
F…·⌊ζ⌈ζ«
Loop over the x-coordinates.
≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε
Loop over the y-coordinates, extracting and concatenating all of the strings at the given coordinates.
⮌ε
Print the strings in reverse order as the y-coordinates are reversed compared to Charcoal's coordinate system.
M⌈EεLκ±Lε
Move to the start of the next column.
$endgroup$
Charcoal, 60 bytes
≔Eθ§ι¹η≔Eθ§ι⁰ζF…·⌊ζ⌈ζ«≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε⮌εM⌈EεLκ±Lε
Try it online! Link is to verbose version of code. Explanation:
≔Eθ§ι¹η≔Eθ§ι⁰ζ
Extract the coordinates from the input.
F…·⌊ζ⌈ζ«
Loop over the x-coordinates.
≔E…·⌊η⌈η⭆θ⎇∧⁼ι§μ⁰⁼κ§μ¹§μ²ωε
Loop over the y-coordinates, extracting and concatenating all of the strings at the given coordinates.
⮌ε
Print the strings in reverse order as the y-coordinates are reversed compared to Charcoal's coordinate system.
M⌈EεLκ±Lε
Move to the start of the next column.
answered 4 hours ago
NeilNeil
80.4k744178
80.4k744178
add a comment |
add a comment |
$begingroup$
Perl 5 -p00
-MList::Util=max
, 148 bytes
s/(S+) (S+) (.*)
/$a{$1}=max$a{$1},length($h{$2}{$1}.=$3);''/ge;for$y(sort{$b-$a}keys%h){map{printf"%-$a{$_}s",$h{$y}{$_}}sort{$a-$b}keys%a;say""}
TIO
How
s/(S+) (S+) (.*)
...
/;''/ge;
, substitution flags/g
loop/e
eval, replacement evaluates to empty clearing line input/default variable
$a{$1}=max$a{$1},length($h{$2}{$1}.=$3)
, autovivifies a map %h of map whose first level keysy
second levelx
and concatenate string$3
to the value, get the length and autovivifies a second map %a whose keysx
and value the max of length over the column (x
)
for$y(sort{$b-$a}keys%h){
...;say""}
, for row indices$y
in keys of%h
sorted numerically reverse,say""
at the end to print a newline
map{
...}sort{$a-$b}keys%a
, for column index$_
in keys %a sorted numerically
printf"%-$a{$_}s",$h{$y}{$_}
, print string aligned to the left with column width
$endgroup$
add a comment |
$begingroup$
Perl 5 -p00
-MList::Util=max
, 148 bytes
s/(S+) (S+) (.*)
/$a{$1}=max$a{$1},length($h{$2}{$1}.=$3);''/ge;for$y(sort{$b-$a}keys%h){map{printf"%-$a{$_}s",$h{$y}{$_}}sort{$a-$b}keys%a;say""}
TIO
How
s/(S+) (S+) (.*)
...
/;''/ge;
, substitution flags/g
loop/e
eval, replacement evaluates to empty clearing line input/default variable
$a{$1}=max$a{$1},length($h{$2}{$1}.=$3)
, autovivifies a map %h of map whose first level keysy
second levelx
and concatenate string$3
to the value, get the length and autovivifies a second map %a whose keysx
and value the max of length over the column (x
)
for$y(sort{$b-$a}keys%h){
...;say""}
, for row indices$y
in keys of%h
sorted numerically reverse,say""
at the end to print a newline
map{
...}sort{$a-$b}keys%a
, for column index$_
in keys %a sorted numerically
printf"%-$a{$_}s",$h{$y}{$_}
, print string aligned to the left with column width
$endgroup$
add a comment |
$begingroup$
Perl 5 -p00
-MList::Util=max
, 148 bytes
s/(S+) (S+) (.*)
/$a{$1}=max$a{$1},length($h{$2}{$1}.=$3);''/ge;for$y(sort{$b-$a}keys%h){map{printf"%-$a{$_}s",$h{$y}{$_}}sort{$a-$b}keys%a;say""}
TIO
How
s/(S+) (S+) (.*)
...
/;''/ge;
, substitution flags/g
loop/e
eval, replacement evaluates to empty clearing line input/default variable
$a{$1}=max$a{$1},length($h{$2}{$1}.=$3)
, autovivifies a map %h of map whose first level keysy
second levelx
and concatenate string$3
to the value, get the length and autovivifies a second map %a whose keysx
and value the max of length over the column (x
)
for$y(sort{$b-$a}keys%h){
...;say""}
, for row indices$y
in keys of%h
sorted numerically reverse,say""
at the end to print a newline
map{
...}sort{$a-$b}keys%a
, for column index$_
in keys %a sorted numerically
printf"%-$a{$_}s",$h{$y}{$_}
, print string aligned to the left with column width
$endgroup$
Perl 5 -p00
-MList::Util=max
, 148 bytes
s/(S+) (S+) (.*)
/$a{$1}=max$a{$1},length($h{$2}{$1}.=$3);''/ge;for$y(sort{$b-$a}keys%h){map{printf"%-$a{$_}s",$h{$y}{$_}}sort{$a-$b}keys%a;say""}
TIO
How
s/(S+) (S+) (.*)
...
/;''/ge;
, substitution flags/g
loop/e
eval, replacement evaluates to empty clearing line input/default variable
$a{$1}=max$a{$1},length($h{$2}{$1}.=$3)
, autovivifies a map %h of map whose first level keysy
second levelx
and concatenate string$3
to the value, get the length and autovivifies a second map %a whose keysx
and value the max of length over the column (x
)
for$y(sort{$b-$a}keys%h){
...;say""}
, for row indices$y
in keys of%h
sorted numerically reverse,say""
at the end to print a newline
map{
...}sort{$a-$b}keys%a
, for column index$_
in keys %a sorted numerically
printf"%-$a{$_}s",$h{$y}{$_}
, print string aligned to the left with column width
edited 1 hour ago
answered 5 hours ago
Nahuel FouilleulNahuel Fouilleul
2,20029
2,20029
add a comment |
add a comment |
$begingroup$
Clean, 212 206 bytes
import StdEnv,StdLib
? =minList
m=maxList
c=flatten
$a#(x,y,z)=unzip3 a
=flatlines(map c(transpose[[ljustify(m(map length l))k\l<-[reverse[c[s\(u,v,s)<-a|u==i&&v==j]\j<-[?y..m y]]],k<-l]\i<-[?x..m x]]))
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 212 206 bytes
import StdEnv,StdLib
? =minList
m=maxList
c=flatten
$a#(x,y,z)=unzip3 a
=flatlines(map c(transpose[[ljustify(m(map length l))k\l<-[reverse[c[s\(u,v,s)<-a|u==i&&v==j]\j<-[?y..m y]]],k<-l]\i<-[?x..m x]]))
Try it online!
$endgroup$
add a comment |
$begingroup$
Clean, 212 206 bytes
import StdEnv,StdLib
? =minList
m=maxList
c=flatten
$a#(x,y,z)=unzip3 a
=flatlines(map c(transpose[[ljustify(m(map length l))k\l<-[reverse[c[s\(u,v,s)<-a|u==i&&v==j]\j<-[?y..m y]]],k<-l]\i<-[?x..m x]]))
Try it online!
$endgroup$
Clean, 212 206 bytes
import StdEnv,StdLib
? =minList
m=maxList
c=flatten
$a#(x,y,z)=unzip3 a
=flatlines(map c(transpose[[ljustify(m(map length l))k\l<-[reverse[c[s\(u,v,s)<-a|u==i&&v==j]\j<-[?y..m y]]],k<-l]\i<-[?x..m x]]))
Try it online!
edited 39 mins ago
answered 1 hour ago
ΟurousΟurous
6,72211034
6,72211034
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%2f179519%2fborderless-table%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$
sandbox
$endgroup$
– Luis felipe De jesus Munoz
7 hours ago
1
$begingroup$
@KevinCruijssen You can assume there wont be any number or empty spaces only in the input. There can be something like
a a
but never1
or ` ` or1a
or1 1
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
@LuisfelipeDejesusMunoz Thanks. Oh, and one more question I'm sure more people here would want to know: who is Marie? ;p
$endgroup$
– Kevin Cruijssen
4 hours ago
2
$begingroup$
@KevinCruijssen My crush 5 years ago :c
$endgroup$
– Luis felipe De jesus Munoz
4 hours ago
1
$begingroup$
Can we take input as a list of named tuples? Something like this:
(int a,int b,string c)
?$endgroup$
– Embodiment of Ignorance
3 hours ago