Crop ASCII Art Challenge
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:
- the first is the 'start' character of the block - marking the top-left corner
- the second is the 'end' character of the block - marking the bottom-right corner
- the third is some form of multiline text, either a string, or list of strings, or filename, or whatever
The result will be multiline text cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
() (
)
are boxes but these:
)( ) (
( )
are not (with start=(
and end=)
).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
(but this text
is in a box )
So only it is important.
Output:
(but this text
is in a box )
Note the stripping of horizontal whitespace as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even )
really a box?
Output:
(
)
Same start/end: start: / end: / input:
Oh, I get how this could be useful
/----------------------------
| All this text is in a box! |
----------------------------/
Output:
/----------------------------
| All this text is in a box! |
----------------------------/
Invalid input: `start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
Invalid input 2: `start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
code-golf ascii-art
add a comment |Â
up vote
4
down vote
favorite
ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:
- the first is the 'start' character of the block - marking the top-left corner
- the second is the 'end' character of the block - marking the bottom-right corner
- the third is some form of multiline text, either a string, or list of strings, or filename, or whatever
The result will be multiline text cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
() (
)
are boxes but these:
)( ) (
( )
are not (with start=(
and end=)
).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
(but this text
is in a box )
So only it is important.
Output:
(but this text
is in a box )
Note the stripping of horizontal whitespace as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even )
really a box?
Output:
(
)
Same start/end: start: / end: / input:
Oh, I get how this could be useful
/----------------------------
| All this text is in a box! |
----------------------------/
Output:
/----------------------------
| All this text is in a box! |
----------------------------/
Invalid input: `start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
Invalid input 2: `start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
code-golf ascii-art
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
1
clarified, also invalid input
â LambdaBeta
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:
- the first is the 'start' character of the block - marking the top-left corner
- the second is the 'end' character of the block - marking the bottom-right corner
- the third is some form of multiline text, either a string, or list of strings, or filename, or whatever
The result will be multiline text cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
() (
)
are boxes but these:
)( ) (
( )
are not (with start=(
and end=)
).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
(but this text
is in a box )
So only it is important.
Output:
(but this text
is in a box )
Note the stripping of horizontal whitespace as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even )
really a box?
Output:
(
)
Same start/end: start: / end: / input:
Oh, I get how this could be useful
/----------------------------
| All this text is in a box! |
----------------------------/
Output:
/----------------------------
| All this text is in a box! |
----------------------------/
Invalid input: `start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
Invalid input 2: `start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
code-golf ascii-art
ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:
- the first is the 'start' character of the block - marking the top-left corner
- the second is the 'end' character of the block - marking the bottom-right corner
- the third is some form of multiline text, either a string, or list of strings, or filename, or whatever
The result will be multiline text cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
() (
)
are boxes but these:
)( ) (
( )
are not (with start=(
and end=)
).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
(but this text
is in a box )
So only it is important.
Output:
(but this text
is in a box )
Note the stripping of horizontal whitespace as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even )
really a box?
Output:
(
)
Same start/end: start: / end: / input:
Oh, I get how this could be useful
/----------------------------
| All this text is in a box! |
----------------------------/
Output:
/----------------------------
| All this text is in a box! |
----------------------------/
Invalid input: `start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
Invalid input 2: `start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
code-golf ascii-art
code-golf ascii-art
edited 1 hour ago
asked 1 hour ago
LambdaBeta
1,544412
1,544412
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
1
clarified, also invalid input
â LambdaBeta
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago
add a comment |Â
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
1
clarified, also invalid input
â LambdaBeta
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
1
1
clarified, also invalid input
â LambdaBeta
1 hour ago
clarified, also invalid input
â LambdaBeta
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
4
down vote
Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp
Try it online! in the V interpreter
Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
rectangular (
) which is ill
and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as//<cr><c-v>nygv$o0dp
or something like that for far too long :)
â LambdaBeta
1 hour ago
add a comment |Â
up vote
1
down vote
APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-â¨w-â¨âÂÂâ¸âÂÂ=s)âÂÂ(wâÂÂâÂÂâÂÂâ½â¸âÂÂ=s)âÂÂsâÂÂâÂÂâÂÂ
Try it online!
add a comment |Â
up vote
0
down vote
Canvas, 37 bytes
ï½Âóâ´â°ï¼Âï½Ââ¡â½âÂÂ
Xâ¸ï¼ÂJâµâ¶ï¼Ââ¤ÃÂâ¤âµXâ¶â¸â°KâÂÂï¼ÂâÂÂâ¤âÂÂâÂÂâÂÂâÂÂâÂÂï¼Âï¼Â
Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ï¼Â
takes) and 1 byte for getting the subsection.. There must be a better approach
add a comment |Â
up vote
0
down vote
Jelly, 17 bytes
á»´Ã
ÂẹⱮáºÂQr/á¹Âá¹Âþ/Ã
Âá»Âá»´{Y
Try it online!
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp
Try it online! in the V interpreter
Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
rectangular (
) which is ill
and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as//<cr><c-v>nygv$o0dp
or something like that for far too long :)
â LambdaBeta
1 hour ago
add a comment |Â
up vote
4
down vote
Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp
Try it online! in the V interpreter
Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
rectangular (
) which is ill
and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as//<cr><c-v>nygv$o0dp
or something like that for far too long :)
â LambdaBeta
1 hour ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp
Try it online! in the V interpreter
Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
rectangular (
) which is ill
and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp
Try it online! in the V interpreter
Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
rectangular (
) which is ill
and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)
edited 57 mins ago
answered 1 hour ago
DJMcMayhemâ¦
40k11140304
40k11140304
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as//<cr><c-v>nygv$o0dp
or something like that for far too long :)
â LambdaBeta
1 hour ago
add a comment |Â
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as//<cr><c-v>nygv$o0dp
or something like that for far too long :)
â LambdaBeta
1 hour ago
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as
//<cr><c-v>nygv$o0dp
or something like that for far too long :)â LambdaBeta
1 hour ago
Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as
//<cr><c-v>nygv$o0dp
or something like that for far too long :)â LambdaBeta
1 hour ago
add a comment |Â
up vote
1
down vote
APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-â¨w-â¨âÂÂâ¸âÂÂ=s)âÂÂ(wâÂÂâÂÂâÂÂâ½â¸âÂÂ=s)âÂÂsâÂÂâÂÂâÂÂ
Try it online!
add a comment |Â
up vote
1
down vote
APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-â¨w-â¨âÂÂâ¸âÂÂ=s)âÂÂ(wâÂÂâÂÂâÂÂâ½â¸âÂÂ=s)âÂÂsâÂÂâÂÂâÂÂ
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-â¨w-â¨âÂÂâ¸âÂÂ=s)âÂÂ(wâÂÂâÂÂâÂÂâ½â¸âÂÂ=s)âÂÂsâÂÂâÂÂâÂÂ
Try it online!
APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-â¨w-â¨âÂÂâ¸âÂÂ=s)âÂÂ(wâÂÂâÂÂâÂÂâ½â¸âÂÂ=s)âÂÂsâÂÂâÂÂâÂÂ
Try it online!
edited 30 mins ago
answered 35 mins ago
Uriel
11.5k4936
11.5k4936
add a comment |Â
add a comment |Â
up vote
0
down vote
Canvas, 37 bytes
ï½Âóâ´â°ï¼Âï½Ââ¡â½âÂÂ
Xâ¸ï¼ÂJâµâ¶ï¼Ââ¤ÃÂâ¤âµXâ¶â¸â°KâÂÂï¼ÂâÂÂâ¤âÂÂâÂÂâÂÂâÂÂâÂÂï¼Âï¼Â
Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ï¼Â
takes) and 1 byte for getting the subsection.. There must be a better approach
add a comment |Â
up vote
0
down vote
Canvas, 37 bytes
ï½Âóâ´â°ï¼Âï½Ââ¡â½âÂÂ
Xâ¸ï¼ÂJâµâ¶ï¼Ââ¤ÃÂâ¤âµXâ¶â¸â°KâÂÂï¼ÂâÂÂâ¤âÂÂâÂÂâÂÂâÂÂâÂÂï¼Âï¼Â
Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ï¼Â
takes) and 1 byte for getting the subsection.. There must be a better approach
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Canvas, 37 bytes
ï½Âóâ´â°ï¼Âï½Ââ¡â½âÂÂ
Xâ¸ï¼ÂJâµâ¶ï¼Ââ¤ÃÂâ¤âµXâ¶â¸â°KâÂÂï¼ÂâÂÂâ¤âÂÂâÂÂâÂÂâÂÂâÂÂï¼Âï¼Â
Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ï¼Â
takes) and 1 byte for getting the subsection.. There must be a better approach
Canvas, 37 bytes
ï½Âóâ´â°ï¼Âï½Ââ¡â½âÂÂ
Xâ¸ï¼ÂJâµâ¶ï¼Ââ¤ÃÂâ¤âµXâ¶â¸â°KâÂÂï¼ÂâÂÂâ¤âÂÂâÂÂâÂÂâÂÂâÂÂï¼Âï¼Â
Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ï¼Â
takes) and 1 byte for getting the subsection.. There must be a better approach
answered 47 mins ago
dzaima
13k21652
13k21652
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 17 bytes
á»´Ã
ÂẹⱮáºÂQr/á¹Âá¹Âþ/Ã
Âá»Âá»´{Y
Try it online!
add a comment |Â
up vote
0
down vote
Jelly, 17 bytes
á»´Ã
ÂẹⱮáºÂQr/á¹Âá¹Âþ/Ã
Âá»Âá»´{Y
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 17 bytes
á»´Ã
ÂẹⱮáºÂQr/á¹Âá¹Âþ/Ã
Âá»Âá»´{Y
Try it online!
Jelly, 17 bytes
á»´Ã
ÂẹⱮáºÂQr/á¹Âá¹Âþ/Ã
Âá»Âá»´{Y
Try it online!
answered 5 mins ago
Erik the Outgolfer
29.5k42698
29.5k42698
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172132%2fcrop-ascii-art-challenge%23new-answer', 'question_page');
);
Post as a guest
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
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
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
What about a valid box with a line outside that is shorter than the box?
â seadoggie01
1 hour ago
1
clarified, also invalid input
â LambdaBeta
1 hour ago
what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?
â Uriel
1 hour ago
The outcome is much like undefined behaviour in C, don't worry about it, anything goes.
â LambdaBeta
1 hour ago
This is a nasty little challenge: nice job!
â seadoggie01
1 hour ago