Lay out the CarpetLet's do the Wave!Square, diamond, square, diamondLog Scales are for Quitters“As a child, I was told Spiders felt no emotion.”It was just a bugIt was just an input-bugUnfold in all directionsI done did made a spaceship maw!Split it. But not all!The (Easy) Road to Code
Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?
Detecting if an element is found inside a container
Method to test if a number is a perfect power?
Why Were Madagascar and New Zealand Discovered So Late?
How to Reset Passwords on Multiple Websites Easily?
What is the best translation for "slot" in the context of multiplayer video games?
How to check is there any negative term in a large list?
What does the word "Atten" mean?
How easy is it to start Magic from scratch?
How to pronounce the slash sign
Why are there no referendums in the US?
Do the temporary hit points from Reckless Abandon stack if I make multiple attacks on my turn?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
How to write papers efficiently when English isn't my first language?
Large drywall patch supports
How do I find the solutions of the following equation?
How does it work when somebody invests in my business?
How does the UK government determine the size of a mandate?
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
System.debug(JSON.Serialize(o)) Not longer shows full string
How to draw lines on a tikz-cd diagram
How did Doctor Strange see the winning outcome in Avengers: Infinity War?
What is the opposite of 'gravitas'?
Do all network devices need to make routing decisions, regardless of communication across networks or within a network?
Lay out the Carpet
Let's do the Wave!Square, diamond, square, diamondLog Scales are for Quitters“As a child, I was told Spiders felt no emotion.”It was just a bugIt was just an input-bugUnfold in all directionsI done did made a spaceship maw!Split it. But not all!The (Easy) Road to Code
$begingroup$
Inspired by this SO question.
Challenge:
Input:
- A string $s$
- A character $c$
Output:
Create a diamond-square ASCII art of the string in all four directions, with the first character of the string in the center and going outwards. Which is inside a square ASCII-art carpet, with the character as filler. This may sound pretty vague, so here an example:
Input: $s$ = string
, $c$ = .
Output:
..........g..........
........g.n.g........
......g.n.i.n.g......
....g.n.i.r.i.n.g....
..g.n.i.r.t.r.i.n.g..
g.n.i.r.t.s.t.r.i.n.g
..g.n.i.r.t.r.i.n.g..
....g.n.i.r.i.n.g....
......g.n.i.n.g......
........g.n.g........
..........g..........
Challenge rules:
- Input-string may also be a list of characters
- Output may also be a list of string-lines or matrix of characters
- Input-string and character are guaranteed to be non-empty
- The string is guaranteed to not contain the character
- Both string and character will only be printable ASCII (unicode range [32,126], space ' ' to and including tilde '~')
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: $s$ = 11111
, $c=$ = 0
Output:
00000000100000000
00000010101000000
00001010101010000
00101010101010100
10101010101010101
00101010101010100
00001010101010000
00000010101000000
00000000100000000
Input: $s$ = 12345ABCDEF
, $c$ = #
Output:
####################F####################
##################F#E#F##################
################F#E#D#E#F################
##############F#E#D#C#D#E#F##############
############F#E#D#C#B#C#D#E#F############
##########F#E#D#C#B#A#B#C#D#E#F##########
########F#E#D#C#B#A#5#A#B#C#D#E#F########
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
F#E#D#C#B#A#5#4#3#2#1#2#3#4#5#A#B#C#D#E#F
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
########F#E#D#C#B#A#5#A#B#C#D#E#F########
##########F#E#D#C#B#A#B#C#D#E#F##########
############F#E#D#C#B#C#D#E#F############
##############F#E#D#C#D#E#F##############
################F#E#D#E#F################
##################F#E#F##################
####################F####################
Input: $s$ = @+-|-o-|-O
, $c$ = :
Output:
::::::::::::::::::O::::::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
O:-:|:-:o:-:|:-:+:@:+:-:|:-:o:-:|:-:O
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::::::O::::::::::::::::::
Input: $s$ = AB
, $c$ = c
Output:
ccBcc
BcAcB
ccBcc
Input: $s$ = ~
, $c$ = X
Output:
~
Input: $s$ = /^/
, $c$ = X
Output:
XXXXXXXXXXXXXXXX
XXXXXXX/XXXXXXX
XXXXX/X^X/XXXXX
XXX/X^XX^X/XXX
X/X^XX/XX^X/X
XXX/X^XX^X/XXX
XXXXX/X^X/XXXXX
XXXXXXX/XXXXXXX
XXXXXXXXXXXXXXXX
code-golf string ascii-art
$endgroup$
|
show 1 more comment
$begingroup$
Inspired by this SO question.
Challenge:
Input:
- A string $s$
- A character $c$
Output:
Create a diamond-square ASCII art of the string in all four directions, with the first character of the string in the center and going outwards. Which is inside a square ASCII-art carpet, with the character as filler. This may sound pretty vague, so here an example:
Input: $s$ = string
, $c$ = .
Output:
..........g..........
........g.n.g........
......g.n.i.n.g......
....g.n.i.r.i.n.g....
..g.n.i.r.t.r.i.n.g..
g.n.i.r.t.s.t.r.i.n.g
..g.n.i.r.t.r.i.n.g..
....g.n.i.r.i.n.g....
......g.n.i.n.g......
........g.n.g........
..........g..........
Challenge rules:
- Input-string may also be a list of characters
- Output may also be a list of string-lines or matrix of characters
- Input-string and character are guaranteed to be non-empty
- The string is guaranteed to not contain the character
- Both string and character will only be printable ASCII (unicode range [32,126], space ' ' to and including tilde '~')
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: $s$ = 11111
, $c=$ = 0
Output:
00000000100000000
00000010101000000
00001010101010000
00101010101010100
10101010101010101
00101010101010100
00001010101010000
00000010101000000
00000000100000000
Input: $s$ = 12345ABCDEF
, $c$ = #
Output:
####################F####################
##################F#E#F##################
################F#E#D#E#F################
##############F#E#D#C#D#E#F##############
############F#E#D#C#B#C#D#E#F############
##########F#E#D#C#B#A#B#C#D#E#F##########
########F#E#D#C#B#A#5#A#B#C#D#E#F########
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
F#E#D#C#B#A#5#4#3#2#1#2#3#4#5#A#B#C#D#E#F
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
########F#E#D#C#B#A#5#A#B#C#D#E#F########
##########F#E#D#C#B#A#B#C#D#E#F##########
############F#E#D#C#B#C#D#E#F############
##############F#E#D#C#D#E#F##############
################F#E#D#E#F################
##################F#E#F##################
####################F####################
Input: $s$ = @+-|-o-|-O
, $c$ = :
Output:
::::::::::::::::::O::::::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
O:-:|:-:o:-:|:-:+:@:+:-:|:-:o:-:|:-:O
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::::::O::::::::::::::::::
Input: $s$ = AB
, $c$ = c
Output:
ccBcc
BcAcB
ccBcc
Input: $s$ = ~
, $c$ = X
Output:
~
Input: $s$ = /^/
, $c$ = X
Output:
XXXXXXXXXXXXXXXX
XXXXXXX/XXXXXXX
XXXXX/X^X/XXXXX
XXX/X^XX^X/XXX
X/X^XX/XX^X/X
XXX/X^XX^X/XXX
XXXXX/X^X/XXXXX
XXXXXXX/XXXXXXX
XXXXXXXXXXXXXXXX
code-golf string ascii-art
$endgroup$
$begingroup$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
1
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.()()()
.
$endgroup$
– Filip Haglund
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday
|
show 1 more comment
$begingroup$
Inspired by this SO question.
Challenge:
Input:
- A string $s$
- A character $c$
Output:
Create a diamond-square ASCII art of the string in all four directions, with the first character of the string in the center and going outwards. Which is inside a square ASCII-art carpet, with the character as filler. This may sound pretty vague, so here an example:
Input: $s$ = string
, $c$ = .
Output:
..........g..........
........g.n.g........
......g.n.i.n.g......
....g.n.i.r.i.n.g....
..g.n.i.r.t.r.i.n.g..
g.n.i.r.t.s.t.r.i.n.g
..g.n.i.r.t.r.i.n.g..
....g.n.i.r.i.n.g....
......g.n.i.n.g......
........g.n.g........
..........g..........
Challenge rules:
- Input-string may also be a list of characters
- Output may also be a list of string-lines or matrix of characters
- Input-string and character are guaranteed to be non-empty
- The string is guaranteed to not contain the character
- Both string and character will only be printable ASCII (unicode range [32,126], space ' ' to and including tilde '~')
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: $s$ = 11111
, $c=$ = 0
Output:
00000000100000000
00000010101000000
00001010101010000
00101010101010100
10101010101010101
00101010101010100
00001010101010000
00000010101000000
00000000100000000
Input: $s$ = 12345ABCDEF
, $c$ = #
Output:
####################F####################
##################F#E#F##################
################F#E#D#E#F################
##############F#E#D#C#D#E#F##############
############F#E#D#C#B#C#D#E#F############
##########F#E#D#C#B#A#B#C#D#E#F##########
########F#E#D#C#B#A#5#A#B#C#D#E#F########
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
F#E#D#C#B#A#5#4#3#2#1#2#3#4#5#A#B#C#D#E#F
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
########F#E#D#C#B#A#5#A#B#C#D#E#F########
##########F#E#D#C#B#A#B#C#D#E#F##########
############F#E#D#C#B#C#D#E#F############
##############F#E#D#C#D#E#F##############
################F#E#D#E#F################
##################F#E#F##################
####################F####################
Input: $s$ = @+-|-o-|-O
, $c$ = :
Output:
::::::::::::::::::O::::::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
O:-:|:-:o:-:|:-:+:@:+:-:|:-:o:-:|:-:O
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::::::O::::::::::::::::::
Input: $s$ = AB
, $c$ = c
Output:
ccBcc
BcAcB
ccBcc
Input: $s$ = ~
, $c$ = X
Output:
~
Input: $s$ = /^/
, $c$ = X
Output:
XXXXXXXXXXXXXXXX
XXXXXXX/XXXXXXX
XXXXX/X^X/XXXXX
XXX/X^XX^X/XXX
X/X^XX/XX^X/X
XXX/X^XX^X/XXX
XXXXX/X^X/XXXXX
XXXXXXX/XXXXXXX
XXXXXXXXXXXXXXXX
code-golf string ascii-art
$endgroup$
Inspired by this SO question.
Challenge:
Input:
- A string $s$
- A character $c$
Output:
Create a diamond-square ASCII art of the string in all four directions, with the first character of the string in the center and going outwards. Which is inside a square ASCII-art carpet, with the character as filler. This may sound pretty vague, so here an example:
Input: $s$ = string
, $c$ = .
Output:
..........g..........
........g.n.g........
......g.n.i.n.g......
....g.n.i.r.i.n.g....
..g.n.i.r.t.r.i.n.g..
g.n.i.r.t.s.t.r.i.n.g
..g.n.i.r.t.r.i.n.g..
....g.n.i.r.i.n.g....
......g.n.i.n.g......
........g.n.g........
..........g..........
Challenge rules:
- Input-string may also be a list of characters
- Output may also be a list of string-lines or matrix of characters
- Input-string and character are guaranteed to be non-empty
- The string is guaranteed to not contain the character
- Both string and character will only be printable ASCII (unicode range [32,126], space ' ' to and including tilde '~')
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: $s$ = 11111
, $c=$ = 0
Output:
00000000100000000
00000010101000000
00001010101010000
00101010101010100
10101010101010101
00101010101010100
00001010101010000
00000010101000000
00000000100000000
Input: $s$ = 12345ABCDEF
, $c$ = #
Output:
####################F####################
##################F#E#F##################
################F#E#D#E#F################
##############F#E#D#C#D#E#F##############
############F#E#D#C#B#C#D#E#F############
##########F#E#D#C#B#A#B#C#D#E#F##########
########F#E#D#C#B#A#5#A#B#C#D#E#F########
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
F#E#D#C#B#A#5#4#3#2#1#2#3#4#5#A#B#C#D#E#F
##F#E#D#C#B#A#5#4#3#2#3#4#5#A#B#C#D#E#F##
####F#E#D#C#B#A#5#4#3#4#5#A#B#C#D#E#F####
######F#E#D#C#B#A#5#4#5#A#B#C#D#E#F######
########F#E#D#C#B#A#5#A#B#C#D#E#F########
##########F#E#D#C#B#A#B#C#D#E#F##########
############F#E#D#C#B#C#D#E#F############
##############F#E#D#C#D#E#F##############
################F#E#D#E#F################
##################F#E#F##################
####################F####################
Input: $s$ = @+-|-o-|-O
, $c$ = :
Output:
::::::::::::::::::O::::::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
O:-:|:-:o:-:|:-:+:@:+:-:|:-:o:-:|:-:O
::O:-:|:-:o:-:|:-:+:-:|:-:o:-:|:-:O::
::::O:-:|:-:o:-:|:-:|:-:o:-:|:-:O::::
::::::O:-:|:-:o:-:|:-:o:-:|:-:O::::::
::::::::O:-:|:-:o:-:o:-:|:-:O::::::::
::::::::::O:-:|:-:o:-:|:-:O::::::::::
::::::::::::O:-:|:-:|:-:O::::::::::::
::::::::::::::O:-:|:-:O::::::::::::::
::::::::::::::::O:-:O::::::::::::::::
::::::::::::::::::O::::::::::::::::::
Input: $s$ = AB
, $c$ = c
Output:
ccBcc
BcAcB
ccBcc
Input: $s$ = ~
, $c$ = X
Output:
~
Input: $s$ = /^/
, $c$ = X
Output:
XXXXXXXXXXXXXXXX
XXXXXXX/XXXXXXX
XXXXX/X^X/XXXXX
XXX/X^XX^X/XXX
X/X^XX/XX^X/X
XXX/X^XX^X/XXX
XXXXX/X^X/XXXXX
XXXXXXX/XXXXXXX
XXXXXXXXXXXXXXXX
code-golf string ascii-art
code-golf string ascii-art
edited yesterday
Kevin Cruijssen
asked yesterday
Kevin CruijssenKevin Cruijssen
41.7k568217
41.7k568217
$begingroup$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
1
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.()()()
.
$endgroup$
– Filip Haglund
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday
|
show 1 more comment
$begingroup$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
1
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.()()()
.
$endgroup$
– Filip Haglund
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
$begingroup$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
1
1
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
1
1
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.
()()()
.$endgroup$
– Filip Haglund
yesterday
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.
()()()
.$endgroup$
– Filip Haglund
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday
|
show 1 more comment
22 Answers
22
active
oldest
votes
$begingroup$
Python 2, 97 96 90 84 bytes
def f(s,c):r=range(len(s));return[c.join(c*i+s[:i:-1]+s[i:]+c*i)for i in r[:0:-1]+r]
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 15 11 bytes
.sûsζøsýí€û
Try it online!
or as a Test Suite
Explanation
.s # push suffixes of input
û # palendromize this list
sζ # transpose using the second input as filler
ø # transpose back
sý # merge each on the second input
í # reverse each row
€û # palendromize each row
$endgroup$
$begingroup$
I'm afraid the reflects cause the last test case/^/
to fail, since thebecomes
/
and vice-versa.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the»
to the footer. :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
add a comment |
$begingroup$
R, 118 bytes
function(a,d,n=length(a))for(i in c(n:1,1:n)[-n])cat(z<-rep(d,2*i-2),paste(c(a[n:i],a[0:-i]),collapse=d),z,'
',sep='')
Try it online!
Thanks to Giuseppe for locating and fixing an error.
$endgroup$
$begingroup$
I guess I need to drop my aversion tofor
loops in R, at least for golfing.
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
add a comment |
$begingroup$
Japt, 15 bytes
Returns an array of lines
Ôå+ ®¬qV êÃûV ê
Try it
Ôå+ ®¬qV êÃûV ê :Implicit input of strings U=s & V=c
Ô :Reverse U
å+ :Prefixes
® :Map
¬ : Split
qV : Join with V
ê : Palindromise
à :End map
ûV :Centre pad each string with V, to the length of the longest
ê :Palindromise
$endgroup$
add a comment |
$begingroup$
Charcoal, 15 bytes
UBηEθ✂θκ‖O↑←UE¹
Try it online! Link is to verbose version of code. Originally submitted as a comment on the now deleted sandbox post. Explanation:
UBη
Set the background to the second input c
.
Eθ✂θκ
Map over the first input s
to generate all suffixes and implicitly print them on separate lines.
‖O↑←
Reflect horizontally and vertically.
UE¹
Add extra space horizontally.
$endgroup$
add a comment |
$begingroup$
J, 59 56 bytes
,~[:((0-2*#).[:,0,:"0(:>:t)*t=:]+/<:)[:(.,])#@]
Try it online!
Too long solution for J ... (entirely my fault)
$endgroup$
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
add a comment |
$begingroup$
R, an ugly 118 bytes version
By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.
function(s,C,l=length(s),L=4*l-3,k=2*l-1,y=abs(rep(1:k,L)-l)+abs(rep(1:L,e=k)-k)/2+1)matrix(ifelse(y%%1|y>l,C,s[y]),k)
Try it online!
R, 161 157 bytes
saved 4 bytes by using ifelse instead of conditionally modifying y
function(S,C,l=nchar(S),L=4*l-3,k=2*l-1,y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1)cat(rbind(matrix(ifelse(y%%1|y>l,C,el(strsplit(S,''))[y]),L),'
'),sep='')
Try it online!
ungolfed and commented
function(S,C)
s=el(strsplit(S,''))
l=nchar(S)
L=4*l-3
k=2*l-1
y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
y[!!y%%1]=l+1 # set non integers to one more than length of string
y[y>l]=l+1 # set number beyond length of string to one more than length of string
M = rbind(matrix(c(s,C)[y],L),'n') # build matrix and add line returns
cat(M,sep='') # print the matrix as a string
hmmm, seems like the longest answer so far!
$endgroup$
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
add a comment |
$begingroup$
Wolfram Language (Mathematica), 121 bytes
Join[q=Table[(v=Table[#2,2(l-k)])<>Riffle[Join[(h=Reverse)[n=(g=Take)[#,-k]],g[n,-k+1]],#2]<>v,k,l=Length@#],Rest@h@q]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 16 bytes
Note: I'll golf it :)
Ôå+ ®¬qVÃùV mê ê
Try it online!
$endgroup$
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
PowerShell, 120 bytes
param($s,$c)($s,(($l=$s.length-1)..0+1..$l|%($x=$c*(2*$_))+($s[($_,($l..$_+($_+1)..$l))[$_-ne$l]]-join$c)+$x))[$l-gt0]
Try it online!
Some days, having index ranges instead of slices really hurts. Today is one of those days. Due to conjoined ranges messing up when dealing with single elements (e.g. returning 0..0+1..0), special-casing is used to avoid it altogether (at the cost of many bytes).
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
jÐƤṚzṚŒḄZŒḄ
Try it online!
Left argument: $s$.
Right argument: $c$ (as a single character, not as a string).
Output: List of Jelly strings (appears as a list of lists of 1-char Python strings, replace ŒṘ
with Y
to see the n
-joined output).
$endgroup$
add a comment |
$begingroup$
PowerShell, 82 83 bytes
+2 bytes thanks Veskah: the single character case bug fixed
-1 byte: The rule Input-string may also be a list of characters
used
$c,$s=$args
($s|%(-join$s)[($r=$i..0+1..$i)]|%"$_"[$r]-join$c
Try it online!
Less golfed:
$c,$s=$args
$southEast = $s|%% substring $i) + $c*$i++
$range=$i..0+1..$i
$southEast[$range]|%
"$_"[$range]-join$c
$endgroup$
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
add a comment |
$begingroup$
Ruby, 95 84 75 bytes
->a,c(1...2*z=a.size).map
Try it online!
Takes input string as an array of chars. Returns an array of strings.
$endgroup$
add a comment |
$begingroup$
Japt, 15 bytes
Ôå+ ê ®ê ¬qV
ûV
Try it
$endgroup$
add a comment |
$begingroup$
Perl 5 with -lF
, -M5.010
, 71 bytes
$"=<>;$A=abs,$_="@F[$A..$#F]".$"x($A*2),/./,say reverse.$' for-$#F..$#F
Try it online!
$endgroup$
add a comment |
$begingroup$
Pip, 24 20 bytes
QPRV:_JbMa@>RV,#aZDb
Use the -l
flag to get human-readable output. Try it online!
Explanation
QPRV:_JbMa@>RV,#aZDb
a,b are cmdline args (implicit)
a 1st cmdline arg (the string)
# Length
, Range
RV Reverse
a@> Take slices of a starting at those indices
ZDb Zip the list of slices together, filling out missing values in
the matrix with b (the character)
M To each row, map this function:
_Jb Join on b
RV: Reverse (making top row the bottom and vice versa)
QP Quad-palindromize: reflect downward and rightward, with overlap
For example, with inputs of abcd
and .
:
RV,#a
[3 2 1 0]
a@>
["d" "cd" "bcd" "abcd"]
ZDb
[['d 'c 'b 'a] ['. 'd 'c 'b] ['. '. 'd 'c] ['. '. '. 'd]]
_JbM
["d.c.b.a" "..d.c.b" "....d.c" "......d"]
RV:
["......d" "....d.c" "..d.c.b" "d.c.b.a"]
QP
["......d......" "....d.c.d...." "..d.c.b.c.d.." "d.c.b.a.b.c.d" "..d.c.b.c.d.." "....d.c.d...." "......d......"]
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 249 bytes
s=>c=>var r=s.Select((x,_)=>int k=s.Length;var m=s.Substring(_,k-_).Aggregate("",(a,b)=>a+c+b);return new string(m.Skip(2).Reverse().Concat(m.Skip(1)).ToArray()).PadLeft(2*k-3+m.Length,c).PadRight(4*k-3,c););return r.Skip(1).Reverse().Concat(r);
Try it online!
This must be improvable...
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 38 bytes
x
Try it online!
$endgroup$
add a comment |
$begingroup$
Canvas, 8 bytes
R±[]/┼┼*
Try it here!
7 bytes but mirrors a bunch of chars.
$endgroup$
add a comment |
$begingroup$
TSQL query, 200 bytes
In MS-SQL Server Management Studio press Ctrl-T before running this query, this will change the output to text.
This script is building up the output from left to right in one long "string", calculating the value to put in each position, output starts with a line-break. The output is limited to 4096 characters.
Golfed:
USE master
DECLARE
@y char='.',
@ varchar(20) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1),@y)+iif((n+1)%k=0,char(13)),'')FROM(SELECT
abs(k/2-n%k)+abs(k/2-n/k)h,*FROM(SELECT
number n,len(@)*2-1k,*FROM spt_values)c)d
WHERE n<k*k and'P'=type
Ungolfed:
USE master
DECLARE
@y char='.',
@ varchar(32) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1))+iif((n+1)%k=0,char(13),@y),'')
FROM
(
SELECT abs(k/2-n%k)+abs(k/2-n/k)h,*
FROM
(
SELECT number n,len(@)*2-1k,*
FROM spt_values
)c
WHERE n<k*k and'P'=type
)d
I had to make some changes to format the output in the online version.
Try it online
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 143 bytes
(s,c)=>q=Math.abs;m=(l=s.length*4-3)-1;for(i=j=0;j<l/2;(i=(++i)%l)?0:++j)p=s[q(i-m/2)/2+q(j-m/4)];process.stdout.write((i?"":"n")+(p?
p:c))
Try it online!
A bit more thinkering would lead to calculating in terms of a one-dimensional array, and less bytes.
$endgroup$
add a comment |
$begingroup$
Perl 6, 79 bytes
->cmap ,g .[^*X+(^$_,)]o*.comb
my&g=.[$_-1...0...$_-1]
Try it online!
Anonymous codeblock that takes input curried (like f(char)(string)
) and returns a list of strings. I think a different approach would be shorter.
$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%2f182212%2flay-out-the-carpet%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
22 Answers
22
active
oldest
votes
22 Answers
22
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 97 96 90 84 bytes
def f(s,c):r=range(len(s));return[c.join(c*i+s[:i:-1]+s[i:]+c*i)for i in r[:0:-1]+r]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 97 96 90 84 bytes
def f(s,c):r=range(len(s));return[c.join(c*i+s[:i:-1]+s[i:]+c*i)for i in r[:0:-1]+r]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 97 96 90 84 bytes
def f(s,c):r=range(len(s));return[c.join(c*i+s[:i:-1]+s[i:]+c*i)for i in r[:0:-1]+r]
Try it online!
$endgroup$
Python 2, 97 96 90 84 bytes
def f(s,c):r=range(len(s));return[c.join(c*i+s[:i:-1]+s[i:]+c*i)for i in r[:0:-1]+r]
Try it online!
edited yesterday
answered yesterday
TFeldTFeld
16.1k21449
16.1k21449
add a comment |
add a comment |
$begingroup$
05AB1E, 15 11 bytes
.sûsζøsýí€û
Try it online!
or as a Test Suite
Explanation
.s # push suffixes of input
û # palendromize this list
sζ # transpose using the second input as filler
ø # transpose back
sý # merge each on the second input
í # reverse each row
€û # palendromize each row
$endgroup$
$begingroup$
I'm afraid the reflects cause the last test case/^/
to fail, since thebecomes
/
and vice-versa.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the»
to the footer. :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
add a comment |
$begingroup$
05AB1E, 15 11 bytes
.sûsζøsýí€û
Try it online!
or as a Test Suite
Explanation
.s # push suffixes of input
û # palendromize this list
sζ # transpose using the second input as filler
ø # transpose back
sý # merge each on the second input
í # reverse each row
€û # palendromize each row
$endgroup$
$begingroup$
I'm afraid the reflects cause the last test case/^/
to fail, since thebecomes
/
and vice-versa.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the»
to the footer. :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
add a comment |
$begingroup$
05AB1E, 15 11 bytes
.sûsζøsýí€û
Try it online!
or as a Test Suite
Explanation
.s # push suffixes of input
û # palendromize this list
sζ # transpose using the second input as filler
ø # transpose back
sý # merge each on the second input
í # reverse each row
€û # palendromize each row
$endgroup$
05AB1E, 15 11 bytes
.sûsζøsýí€û
Try it online!
or as a Test Suite
Explanation
.s # push suffixes of input
û # palendromize this list
sζ # transpose using the second input as filler
ø # transpose back
sý # merge each on the second input
í # reverse each row
€û # palendromize each row
edited yesterday
answered yesterday
EmignaEmigna
47.2k433143
47.2k433143
$begingroup$
I'm afraid the reflects cause the last test case/^/
to fail, since thebecomes
/
and vice-versa.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the»
to the footer. :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
add a comment |
$begingroup$
I'm afraid the reflects cause the last test case/^/
to fail, since thebecomes
/
and vice-versa.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the»
to the footer. :)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
$begingroup$
I'm afraid the reflects cause the last test case
/^/
to fail, since the
becomes /
and vice-versa.$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
I'm afraid the reflects cause the last test case
/^/
to fail, since the
becomes /
and vice-versa.$endgroup$
– Kevin Cruijssen
yesterday
1
1
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
@KevinCruijssen: Yeah. Fortunately it didn't cost any bytes to fix it. I still feel as if there should be a better way of doing this though, so I'll keep looking.
$endgroup$
– Emigna
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the
»
to the footer. :)$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
"Output may also be a list of string-lines or matrix of characters", so you can move the
»
to the footer. :)$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
$begingroup$
@KevinCruijssen Ah right. I glanced over that part. Thanks :)
$endgroup$
– Emigna
yesterday
add a comment |
$begingroup$
R, 118 bytes
function(a,d,n=length(a))for(i in c(n:1,1:n)[-n])cat(z<-rep(d,2*i-2),paste(c(a[n:i],a[0:-i]),collapse=d),z,'
',sep='')
Try it online!
Thanks to Giuseppe for locating and fixing an error.
$endgroup$
$begingroup$
I guess I need to drop my aversion tofor
loops in R, at least for golfing.
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
add a comment |
$begingroup$
R, 118 bytes
function(a,d,n=length(a))for(i in c(n:1,1:n)[-n])cat(z<-rep(d,2*i-2),paste(c(a[n:i],a[0:-i]),collapse=d),z,'
',sep='')
Try it online!
Thanks to Giuseppe for locating and fixing an error.
$endgroup$
$begingroup$
I guess I need to drop my aversion tofor
loops in R, at least for golfing.
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
add a comment |
$begingroup$
R, 118 bytes
function(a,d,n=length(a))for(i in c(n:1,1:n)[-n])cat(z<-rep(d,2*i-2),paste(c(a[n:i],a[0:-i]),collapse=d),z,'
',sep='')
Try it online!
Thanks to Giuseppe for locating and fixing an error.
$endgroup$
R, 118 bytes
function(a,d,n=length(a))for(i in c(n:1,1:n)[-n])cat(z<-rep(d,2*i-2),paste(c(a[n:i],a[0:-i]),collapse=d),z,'
',sep='')
Try it online!
Thanks to Giuseppe for locating and fixing an error.
edited yesterday
answered yesterday
Kirill L.Kirill L.
5,8731526
5,8731526
$begingroup$
I guess I need to drop my aversion tofor
loops in R, at least for golfing.
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
add a comment |
$begingroup$
I guess I need to drop my aversion tofor
loops in R, at least for golfing.
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
$begingroup$
I guess I need to drop my aversion to
for
loops in R, at least for golfing.$endgroup$
– Aaron Hayman
yesterday
$begingroup$
I guess I need to drop my aversion to
for
loops in R, at least for golfing.$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
$begingroup$
@Giuseppe, thanks, I shouldn't be so lazy about inclusion of extra test cases!
$endgroup$
– Kirill L.
yesterday
add a comment |
$begingroup$
Japt, 15 bytes
Returns an array of lines
Ôå+ ®¬qV êÃûV ê
Try it
Ôå+ ®¬qV êÃûV ê :Implicit input of strings U=s & V=c
Ô :Reverse U
å+ :Prefixes
® :Map
¬ : Split
qV : Join with V
ê : Palindromise
à :End map
ûV :Centre pad each string with V, to the length of the longest
ê :Palindromise
$endgroup$
add a comment |
$begingroup$
Japt, 15 bytes
Returns an array of lines
Ôå+ ®¬qV êÃûV ê
Try it
Ôå+ ®¬qV êÃûV ê :Implicit input of strings U=s & V=c
Ô :Reverse U
å+ :Prefixes
® :Map
¬ : Split
qV : Join with V
ê : Palindromise
à :End map
ûV :Centre pad each string with V, to the length of the longest
ê :Palindromise
$endgroup$
add a comment |
$begingroup$
Japt, 15 bytes
Returns an array of lines
Ôå+ ®¬qV êÃûV ê
Try it
Ôå+ ®¬qV êÃûV ê :Implicit input of strings U=s & V=c
Ô :Reverse U
å+ :Prefixes
® :Map
¬ : Split
qV : Join with V
ê : Palindromise
à :End map
ûV :Centre pad each string with V, to the length of the longest
ê :Palindromise
$endgroup$
Japt, 15 bytes
Returns an array of lines
Ôå+ ®¬qV êÃûV ê
Try it
Ôå+ ®¬qV êÃûV ê :Implicit input of strings U=s & V=c
Ô :Reverse U
å+ :Prefixes
® :Map
¬ : Split
qV : Join with V
ê : Palindromise
à :End map
ûV :Centre pad each string with V, to the length of the longest
ê :Palindromise
answered yesterday
ShaggyShaggy
19k21667
19k21667
add a comment |
add a comment |
$begingroup$
Charcoal, 15 bytes
UBηEθ✂θκ‖O↑←UE¹
Try it online! Link is to verbose version of code. Originally submitted as a comment on the now deleted sandbox post. Explanation:
UBη
Set the background to the second input c
.
Eθ✂θκ
Map over the first input s
to generate all suffixes and implicitly print them on separate lines.
‖O↑←
Reflect horizontally and vertically.
UE¹
Add extra space horizontally.
$endgroup$
add a comment |
$begingroup$
Charcoal, 15 bytes
UBηEθ✂θκ‖O↑←UE¹
Try it online! Link is to verbose version of code. Originally submitted as a comment on the now deleted sandbox post. Explanation:
UBη
Set the background to the second input c
.
Eθ✂θκ
Map over the first input s
to generate all suffixes and implicitly print them on separate lines.
‖O↑←
Reflect horizontally and vertically.
UE¹
Add extra space horizontally.
$endgroup$
add a comment |
$begingroup$
Charcoal, 15 bytes
UBηEθ✂θκ‖O↑←UE¹
Try it online! Link is to verbose version of code. Originally submitted as a comment on the now deleted sandbox post. Explanation:
UBη
Set the background to the second input c
.
Eθ✂θκ
Map over the first input s
to generate all suffixes and implicitly print them on separate lines.
‖O↑←
Reflect horizontally and vertically.
UE¹
Add extra space horizontally.
$endgroup$
Charcoal, 15 bytes
UBηEθ✂θκ‖O↑←UE¹
Try it online! Link is to verbose version of code. Originally submitted as a comment on the now deleted sandbox post. Explanation:
UBη
Set the background to the second input c
.
Eθ✂θκ
Map over the first input s
to generate all suffixes and implicitly print them on separate lines.
‖O↑←
Reflect horizontally and vertically.
UE¹
Add extra space horizontally.
answered yesterday
NeilNeil
82.1k745178
82.1k745178
add a comment |
add a comment |
$begingroup$
J, 59 56 bytes
,~[:((0-2*#).[:,0,:"0(:>:t)*t=:]+/<:)[:(.,])#@]
Try it online!
Too long solution for J ... (entirely my fault)
$endgroup$
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
add a comment |
$begingroup$
J, 59 56 bytes
,~[:((0-2*#).[:,0,:"0(:>:t)*t=:]+/<:)[:(.,])#@]
Try it online!
Too long solution for J ... (entirely my fault)
$endgroup$
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
add a comment |
$begingroup$
J, 59 56 bytes
,~[:((0-2*#).[:,0,:"0(:>:t)*t=:]+/<:)[:(.,])#@]
Try it online!
Too long solution for J ... (entirely my fault)
$endgroup$
J, 59 56 bytes
,~[:((0-2*#).[:,0,:"0(:>:t)*t=:]+/<:)[:(.,])#@]
Try it online!
Too long solution for J ... (entirely my fault)
edited yesterday
answered yesterday
Galen IvanovGalen Ivanov
7,30211034
7,30211034
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
add a comment |
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
2
2
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
Here’s 39
$endgroup$
– FrownyFrog
10 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
$begingroup$
@FrownyFrog Thanks, I think you should post it as your own solution
$endgroup$
– Galen Ivanov
7 hours ago
add a comment |
$begingroup$
R, an ugly 118 bytes version
By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.
function(s,C,l=length(s),L=4*l-3,k=2*l-1,y=abs(rep(1:k,L)-l)+abs(rep(1:L,e=k)-k)/2+1)matrix(ifelse(y%%1|y>l,C,s[y]),k)
Try it online!
R, 161 157 bytes
saved 4 bytes by using ifelse instead of conditionally modifying y
function(S,C,l=nchar(S),L=4*l-3,k=2*l-1,y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1)cat(rbind(matrix(ifelse(y%%1|y>l,C,el(strsplit(S,''))[y]),L),'
'),sep='')
Try it online!
ungolfed and commented
function(S,C)
s=el(strsplit(S,''))
l=nchar(S)
L=4*l-3
k=2*l-1
y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
y[!!y%%1]=l+1 # set non integers to one more than length of string
y[y>l]=l+1 # set number beyond length of string to one more than length of string
M = rbind(matrix(c(s,C)[y],L),'n') # build matrix and add line returns
cat(M,sep='') # print the matrix as a string
hmmm, seems like the longest answer so far!
$endgroup$
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
add a comment |
$begingroup$
R, an ugly 118 bytes version
By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.
function(s,C,l=length(s),L=4*l-3,k=2*l-1,y=abs(rep(1:k,L)-l)+abs(rep(1:L,e=k)-k)/2+1)matrix(ifelse(y%%1|y>l,C,s[y]),k)
Try it online!
R, 161 157 bytes
saved 4 bytes by using ifelse instead of conditionally modifying y
function(S,C,l=nchar(S),L=4*l-3,k=2*l-1,y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1)cat(rbind(matrix(ifelse(y%%1|y>l,C,el(strsplit(S,''))[y]),L),'
'),sep='')
Try it online!
ungolfed and commented
function(S,C)
s=el(strsplit(S,''))
l=nchar(S)
L=4*l-3
k=2*l-1
y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
y[!!y%%1]=l+1 # set non integers to one more than length of string
y[y>l]=l+1 # set number beyond length of string to one more than length of string
M = rbind(matrix(c(s,C)[y],L),'n') # build matrix and add line returns
cat(M,sep='') # print the matrix as a string
hmmm, seems like the longest answer so far!
$endgroup$
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
add a comment |
$begingroup$
R, an ugly 118 bytes version
By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.
function(s,C,l=length(s),L=4*l-3,k=2*l-1,y=abs(rep(1:k,L)-l)+abs(rep(1:L,e=k)-k)/2+1)matrix(ifelse(y%%1|y>l,C,s[y]),k)
Try it online!
R, 161 157 bytes
saved 4 bytes by using ifelse instead of conditionally modifying y
function(S,C,l=nchar(S),L=4*l-3,k=2*l-1,y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1)cat(rbind(matrix(ifelse(y%%1|y>l,C,el(strsplit(S,''))[y]),L),'
'),sep='')
Try it online!
ungolfed and commented
function(S,C)
s=el(strsplit(S,''))
l=nchar(S)
L=4*l-3
k=2*l-1
y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
y[!!y%%1]=l+1 # set non integers to one more than length of string
y[y>l]=l+1 # set number beyond length of string to one more than length of string
M = rbind(matrix(c(s,C)[y],L),'n') # build matrix and add line returns
cat(M,sep='') # print the matrix as a string
hmmm, seems like the longest answer so far!
$endgroup$
R, an ugly 118 bytes version
By letting the input be a vector of single characters, and outputting a matrix instead of printing nice ascii art.
function(s,C,l=length(s),L=4*l-3,k=2*l-1,y=abs(rep(1:k,L)-l)+abs(rep(1:L,e=k)-k)/2+1)matrix(ifelse(y%%1|y>l,C,s[y]),k)
Try it online!
R, 161 157 bytes
saved 4 bytes by using ifelse instead of conditionally modifying y
function(S,C,l=nchar(S),L=4*l-3,k=2*l-1,y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1)cat(rbind(matrix(ifelse(y%%1|y>l,C,el(strsplit(S,''))[y]),L),'
'),sep='')
Try it online!
ungolfed and commented
function(S,C)
s=el(strsplit(S,''))
l=nchar(S)
L=4*l-3
k=2*l-1
y=abs(rep(1:L,k)-k)/2+abs(rep(1:k,e=L)-l)+1 # distance from centre
y[!!y%%1]=l+1 # set non integers to one more than length of string
y[y>l]=l+1 # set number beyond length of string to one more than length of string
M = rbind(matrix(c(s,C)[y],L),'n') # build matrix and add line returns
cat(M,sep='') # print the matrix as a string
hmmm, seems like the longest answer so far!
edited yesterday
answered yesterday
Aaron HaymanAaron Hayman
3115
3115
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
add a comment |
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
Oh dear, should have looked at the question better
$endgroup$
– Aaron Hayman
yesterday
1
1
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
$begingroup$
@KevinCruijssen I have fixed it now
$endgroup$
– Aaron Hayman
yesterday
1
1
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
$begingroup$
for +15 bytes, you can make your ugly answer ascii-art: Try it online!
$endgroup$
– Giuseppe
yesterday
add a comment |
$begingroup$
Wolfram Language (Mathematica), 121 bytes
Join[q=Table[(v=Table[#2,2(l-k)])<>Riffle[Join[(h=Reverse)[n=(g=Take)[#,-k]],g[n,-k+1]],#2]<>v,k,l=Length@#],Rest@h@q]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 121 bytes
Join[q=Table[(v=Table[#2,2(l-k)])<>Riffle[Join[(h=Reverse)[n=(g=Take)[#,-k]],g[n,-k+1]],#2]<>v,k,l=Length@#],Rest@h@q]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 121 bytes
Join[q=Table[(v=Table[#2,2(l-k)])<>Riffle[Join[(h=Reverse)[n=(g=Take)[#,-k]],g[n,-k+1]],#2]<>v,k,l=Length@#],Rest@h@q]&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 121 bytes
Join[q=Table[(v=Table[#2,2(l-k)])<>Riffle[Join[(h=Reverse)[n=(g=Take)[#,-k]],g[n,-k+1]],#2]<>v,k,l=Length@#],Rest@h@q]&
Try it online!
answered yesterday
J42161217J42161217
13.6k21252
13.6k21252
add a comment |
add a comment |
$begingroup$
Japt, 16 bytes
Note: I'll golf it :)
Ôå+ ®¬qVÃùV mê ê
Try it online!
$endgroup$
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
Japt, 16 bytes
Note: I'll golf it :)
Ôå+ ®¬qVÃùV mê ê
Try it online!
$endgroup$
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
Japt, 16 bytes
Note: I'll golf it :)
Ôå+ ®¬qVÃùV mê ê
Try it online!
$endgroup$
Japt, 16 bytes
Note: I'll golf it :)
Ôå+ ®¬qVÃùV mê ê
Try it online!
answered yesterday
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,69821671
5,69821671
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
It's fairly similar to the other Japt answer, but in a different order, isn't it? I don't know Japt, but I see similar characters in both answers. ;)
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen Yeah, both are almost the same, for now
$endgroup$
– Luis felipe De jesus Munoz
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
$begingroup$
@KevinCruijssen, Luis developed this independently from my solution.
$endgroup$
– Shaggy
yesterday
add a comment |
$begingroup$
PowerShell, 120 bytes
param($s,$c)($s,(($l=$s.length-1)..0+1..$l|%($x=$c*(2*$_))+($s[($_,($l..$_+($_+1)..$l))[$_-ne$l]]-join$c)+$x))[$l-gt0]
Try it online!
Some days, having index ranges instead of slices really hurts. Today is one of those days. Due to conjoined ranges messing up when dealing with single elements (e.g. returning 0..0+1..0), special-casing is used to avoid it altogether (at the cost of many bytes).
$endgroup$
add a comment |
$begingroup$
PowerShell, 120 bytes
param($s,$c)($s,(($l=$s.length-1)..0+1..$l|%($x=$c*(2*$_))+($s[($_,($l..$_+($_+1)..$l))[$_-ne$l]]-join$c)+$x))[$l-gt0]
Try it online!
Some days, having index ranges instead of slices really hurts. Today is one of those days. Due to conjoined ranges messing up when dealing with single elements (e.g. returning 0..0+1..0), special-casing is used to avoid it altogether (at the cost of many bytes).
$endgroup$
add a comment |
$begingroup$
PowerShell, 120 bytes
param($s,$c)($s,(($l=$s.length-1)..0+1..$l|%($x=$c*(2*$_))+($s[($_,($l..$_+($_+1)..$l))[$_-ne$l]]-join$c)+$x))[$l-gt0]
Try it online!
Some days, having index ranges instead of slices really hurts. Today is one of those days. Due to conjoined ranges messing up when dealing with single elements (e.g. returning 0..0+1..0), special-casing is used to avoid it altogether (at the cost of many bytes).
$endgroup$
PowerShell, 120 bytes
param($s,$c)($s,(($l=$s.length-1)..0+1..$l|%($x=$c*(2*$_))+($s[($_,($l..$_+($_+1)..$l))[$_-ne$l]]-join$c)+$x))[$l-gt0]
Try it online!
Some days, having index ranges instead of slices really hurts. Today is one of those days. Due to conjoined ranges messing up when dealing with single elements (e.g. returning 0..0+1..0), special-casing is used to avoid it altogether (at the cost of many bytes).
edited yesterday
answered yesterday
VeskahVeskah
1,155214
1,155214
add a comment |
add a comment |
$begingroup$
Jelly, 11 bytes
jÐƤṚzṚŒḄZŒḄ
Try it online!
Left argument: $s$.
Right argument: $c$ (as a single character, not as a string).
Output: List of Jelly strings (appears as a list of lists of 1-char Python strings, replace ŒṘ
with Y
to see the n
-joined output).
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
jÐƤṚzṚŒḄZŒḄ
Try it online!
Left argument: $s$.
Right argument: $c$ (as a single character, not as a string).
Output: List of Jelly strings (appears as a list of lists of 1-char Python strings, replace ŒṘ
with Y
to see the n
-joined output).
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
jÐƤṚzṚŒḄZŒḄ
Try it online!
Left argument: $s$.
Right argument: $c$ (as a single character, not as a string).
Output: List of Jelly strings (appears as a list of lists of 1-char Python strings, replace ŒṘ
with Y
to see the n
-joined output).
$endgroup$
Jelly, 11 bytes
jÐƤṚzṚŒḄZŒḄ
Try it online!
Left argument: $s$.
Right argument: $c$ (as a single character, not as a string).
Output: List of Jelly strings (appears as a list of lists of 1-char Python strings, replace ŒṘ
with Y
to see the n
-joined output).
answered yesterday
Erik the OutgolferErik the Outgolfer
32.9k429105
32.9k429105
add a comment |
add a comment |
$begingroup$
PowerShell, 82 83 bytes
+2 bytes thanks Veskah: the single character case bug fixed
-1 byte: The rule Input-string may also be a list of characters
used
$c,$s=$args
($s|%(-join$s)[($r=$i..0+1..$i)]|%"$_"[$r]-join$c
Try it online!
Less golfed:
$c,$s=$args
$southEast = $s|%% substring $i) + $c*$i++
$range=$i..0+1..$i
$southEast[$range]|%
"$_"[$range]-join$c
$endgroup$
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
add a comment |
$begingroup$
PowerShell, 82 83 bytes
+2 bytes thanks Veskah: the single character case bug fixed
-1 byte: The rule Input-string may also be a list of characters
used
$c,$s=$args
($s|%(-join$s)[($r=$i..0+1..$i)]|%"$_"[$r]-join$c
Try it online!
Less golfed:
$c,$s=$args
$southEast = $s|%% substring $i) + $c*$i++
$range=$i..0+1..$i
$southEast[$range]|%
"$_"[$range]-join$c
$endgroup$
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
add a comment |
$begingroup$
PowerShell, 82 83 bytes
+2 bytes thanks Veskah: the single character case bug fixed
-1 byte: The rule Input-string may also be a list of characters
used
$c,$s=$args
($s|%(-join$s)[($r=$i..0+1..$i)]|%"$_"[$r]-join$c
Try it online!
Less golfed:
$c,$s=$args
$southEast = $s|%% substring $i) + $c*$i++
$range=$i..0+1..$i
$southEast[$range]|%
"$_"[$range]-join$c
$endgroup$
PowerShell, 82 83 bytes
+2 bytes thanks Veskah: the single character case bug fixed
-1 byte: The rule Input-string may also be a list of characters
used
$c,$s=$args
($s|%(-join$s)[($r=$i..0+1..$i)]|%"$_"[$r]-join$c
Try it online!
Less golfed:
$c,$s=$args
$southEast = $s|%% substring $i) + $c*$i++
$range=$i..0+1..$i
$southEast[$range]|%
"$_"[$range]-join$c
edited yesterday
answered yesterday
mazzymazzy
2,9351317
2,9351317
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
add a comment |
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
1
1
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for
~
$endgroup$
– Veskah
yesterday
$begingroup$
Looks like this breaks for the single character case. There's just an empty line in the TIO link for
~
$endgroup$
– Veskah
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
$begingroup$
Indeed. Thanks!
$endgroup$
– mazzy
yesterday
add a comment |
$begingroup$
Ruby, 95 84 75 bytes
->a,c(1...2*z=a.size).map
Try it online!
Takes input string as an array of chars. Returns an array of strings.
$endgroup$
add a comment |
$begingroup$
Ruby, 95 84 75 bytes
->a,c(1...2*z=a.size).map
Try it online!
Takes input string as an array of chars. Returns an array of strings.
$endgroup$
add a comment |
$begingroup$
Ruby, 95 84 75 bytes
->a,c(1...2*z=a.size).map
Try it online!
Takes input string as an array of chars. Returns an array of strings.
$endgroup$
Ruby, 95 84 75 bytes
->a,c(1...2*z=a.size).map
Try it online!
Takes input string as an array of chars. Returns an array of strings.
edited yesterday
answered yesterday
Kirill L.Kirill L.
5,8731526
5,8731526
add a comment |
add a comment |
$begingroup$
Japt, 15 bytes
Ôå+ ê ®ê ¬qV
ûV
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 15 bytes
Ôå+ ê ®ê ¬qV
ûV
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 15 bytes
Ôå+ ê ®ê ¬qV
ûV
Try it
$endgroup$
Japt, 15 bytes
Ôå+ ê ®ê ¬qV
ûV
Try it
edited yesterday
answered yesterday
OliverOliver
5,3801832
5,3801832
add a comment |
add a comment |
$begingroup$
Perl 5 with -lF
, -M5.010
, 71 bytes
$"=<>;$A=abs,$_="@F[$A..$#F]".$"x($A*2),/./,say reverse.$' for-$#F..$#F
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 with -lF
, -M5.010
, 71 bytes
$"=<>;$A=abs,$_="@F[$A..$#F]".$"x($A*2),/./,say reverse.$' for-$#F..$#F
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 with -lF
, -M5.010
, 71 bytes
$"=<>;$A=abs,$_="@F[$A..$#F]".$"x($A*2),/./,say reverse.$' for-$#F..$#F
Try it online!
$endgroup$
Perl 5 with -lF
, -M5.010
, 71 bytes
$"=<>;$A=abs,$_="@F[$A..$#F]".$"x($A*2),/./,say reverse.$' for-$#F..$#F
Try it online!
answered yesterday
Dom HastingsDom Hastings
14.9k33270
14.9k33270
add a comment |
add a comment |
$begingroup$
Pip, 24 20 bytes
QPRV:_JbMa@>RV,#aZDb
Use the -l
flag to get human-readable output. Try it online!
Explanation
QPRV:_JbMa@>RV,#aZDb
a,b are cmdline args (implicit)
a 1st cmdline arg (the string)
# Length
, Range
RV Reverse
a@> Take slices of a starting at those indices
ZDb Zip the list of slices together, filling out missing values in
the matrix with b (the character)
M To each row, map this function:
_Jb Join on b
RV: Reverse (making top row the bottom and vice versa)
QP Quad-palindromize: reflect downward and rightward, with overlap
For example, with inputs of abcd
and .
:
RV,#a
[3 2 1 0]
a@>
["d" "cd" "bcd" "abcd"]
ZDb
[['d 'c 'b 'a] ['. 'd 'c 'b] ['. '. 'd 'c] ['. '. '. 'd]]
_JbM
["d.c.b.a" "..d.c.b" "....d.c" "......d"]
RV:
["......d" "....d.c" "..d.c.b" "d.c.b.a"]
QP
["......d......" "....d.c.d...." "..d.c.b.c.d.." "d.c.b.a.b.c.d" "..d.c.b.c.d.." "....d.c.d...." "......d......"]
$endgroup$
add a comment |
$begingroup$
Pip, 24 20 bytes
QPRV:_JbMa@>RV,#aZDb
Use the -l
flag to get human-readable output. Try it online!
Explanation
QPRV:_JbMa@>RV,#aZDb
a,b are cmdline args (implicit)
a 1st cmdline arg (the string)
# Length
, Range
RV Reverse
a@> Take slices of a starting at those indices
ZDb Zip the list of slices together, filling out missing values in
the matrix with b (the character)
M To each row, map this function:
_Jb Join on b
RV: Reverse (making top row the bottom and vice versa)
QP Quad-palindromize: reflect downward and rightward, with overlap
For example, with inputs of abcd
and .
:
RV,#a
[3 2 1 0]
a@>
["d" "cd" "bcd" "abcd"]
ZDb
[['d 'c 'b 'a] ['. 'd 'c 'b] ['. '. 'd 'c] ['. '. '. 'd]]
_JbM
["d.c.b.a" "..d.c.b" "....d.c" "......d"]
RV:
["......d" "....d.c" "..d.c.b" "d.c.b.a"]
QP
["......d......" "....d.c.d...." "..d.c.b.c.d.." "d.c.b.a.b.c.d" "..d.c.b.c.d.." "....d.c.d...." "......d......"]
$endgroup$
add a comment |
$begingroup$
Pip, 24 20 bytes
QPRV:_JbMa@>RV,#aZDb
Use the -l
flag to get human-readable output. Try it online!
Explanation
QPRV:_JbMa@>RV,#aZDb
a,b are cmdline args (implicit)
a 1st cmdline arg (the string)
# Length
, Range
RV Reverse
a@> Take slices of a starting at those indices
ZDb Zip the list of slices together, filling out missing values in
the matrix with b (the character)
M To each row, map this function:
_Jb Join on b
RV: Reverse (making top row the bottom and vice versa)
QP Quad-palindromize: reflect downward and rightward, with overlap
For example, with inputs of abcd
and .
:
RV,#a
[3 2 1 0]
a@>
["d" "cd" "bcd" "abcd"]
ZDb
[['d 'c 'b 'a] ['. 'd 'c 'b] ['. '. 'd 'c] ['. '. '. 'd]]
_JbM
["d.c.b.a" "..d.c.b" "....d.c" "......d"]
RV:
["......d" "....d.c" "..d.c.b" "d.c.b.a"]
QP
["......d......" "....d.c.d...." "..d.c.b.c.d.." "d.c.b.a.b.c.d" "..d.c.b.c.d.." "....d.c.d...." "......d......"]
$endgroup$
Pip, 24 20 bytes
QPRV:_JbMa@>RV,#aZDb
Use the -l
flag to get human-readable output. Try it online!
Explanation
QPRV:_JbMa@>RV,#aZDb
a,b are cmdline args (implicit)
a 1st cmdline arg (the string)
# Length
, Range
RV Reverse
a@> Take slices of a starting at those indices
ZDb Zip the list of slices together, filling out missing values in
the matrix with b (the character)
M To each row, map this function:
_Jb Join on b
RV: Reverse (making top row the bottom and vice versa)
QP Quad-palindromize: reflect downward and rightward, with overlap
For example, with inputs of abcd
and .
:
RV,#a
[3 2 1 0]
a@>
["d" "cd" "bcd" "abcd"]
ZDb
[['d 'c 'b 'a] ['. 'd 'c 'b] ['. '. 'd 'c] ['. '. '. 'd]]
_JbM
["d.c.b.a" "..d.c.b" "....d.c" "......d"]
RV:
["......d" "....d.c" "..d.c.b" "d.c.b.a"]
QP
["......d......" "....d.c.d...." "..d.c.b.c.d.." "d.c.b.a.b.c.d" "..d.c.b.c.d.." "....d.c.d...." "......d......"]
edited 16 hours ago
answered 16 hours ago
DLoscDLosc
19.3k33990
19.3k33990
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 249 bytes
s=>c=>var r=s.Select((x,_)=>int k=s.Length;var m=s.Substring(_,k-_).Aggregate("",(a,b)=>a+c+b);return new string(m.Skip(2).Reverse().Concat(m.Skip(1)).ToArray()).PadLeft(2*k-3+m.Length,c).PadRight(4*k-3,c););return r.Skip(1).Reverse().Concat(r);
Try it online!
This must be improvable...
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 249 bytes
s=>c=>var r=s.Select((x,_)=>int k=s.Length;var m=s.Substring(_,k-_).Aggregate("",(a,b)=>a+c+b);return new string(m.Skip(2).Reverse().Concat(m.Skip(1)).ToArray()).PadLeft(2*k-3+m.Length,c).PadRight(4*k-3,c););return r.Skip(1).Reverse().Concat(r);
Try it online!
This must be improvable...
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 249 bytes
s=>c=>var r=s.Select((x,_)=>int k=s.Length;var m=s.Substring(_,k-_).Aggregate("",(a,b)=>a+c+b);return new string(m.Skip(2).Reverse().Concat(m.Skip(1)).ToArray()).PadLeft(2*k-3+m.Length,c).PadRight(4*k-3,c););return r.Skip(1).Reverse().Concat(r);
Try it online!
This must be improvable...
$endgroup$
C# (Visual C# Interactive Compiler), 249 bytes
s=>c=>var r=s.Select((x,_)=>int k=s.Length;var m=s.Substring(_,k-_).Aggregate("",(a,b)=>a+c+b);return new string(m.Skip(2).Reverse().Concat(m.Skip(1)).ToArray()).PadLeft(2*k-3+m.Length,c).PadRight(4*k-3,c););return r.Skip(1).Reverse().Concat(r);
Try it online!
This must be improvable...
answered 9 hours ago
Expired DataExpired Data
3686
3686
add a comment |
add a comment |
$begingroup$
K (ngn/k), 38 bytes
x
Try it online!
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 38 bytes
x
Try it online!
$endgroup$
add a comment |
$begingroup$
K (ngn/k), 38 bytes
x
Try it online!
$endgroup$
K (ngn/k), 38 bytes
x
Try it online!
edited 9 hours ago
answered 11 hours ago
ngnngn
7,30112560
7,30112560
add a comment |
add a comment |
$begingroup$
Canvas, 8 bytes
R±[]/┼┼*
Try it here!
7 bytes but mirrors a bunch of chars.
$endgroup$
add a comment |
$begingroup$
Canvas, 8 bytes
R±[]/┼┼*
Try it here!
7 bytes but mirrors a bunch of chars.
$endgroup$
add a comment |
$begingroup$
Canvas, 8 bytes
R±[]/┼┼*
Try it here!
7 bytes but mirrors a bunch of chars.
$endgroup$
Canvas, 8 bytes
R±[]/┼┼*
Try it here!
7 bytes but mirrors a bunch of chars.
answered 5 hours ago
dzaimadzaima
15.9k22059
15.9k22059
add a comment |
add a comment |
$begingroup$
TSQL query, 200 bytes
In MS-SQL Server Management Studio press Ctrl-T before running this query, this will change the output to text.
This script is building up the output from left to right in one long "string", calculating the value to put in each position, output starts with a line-break. The output is limited to 4096 characters.
Golfed:
USE master
DECLARE
@y char='.',
@ varchar(20) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1),@y)+iif((n+1)%k=0,char(13)),'')FROM(SELECT
abs(k/2-n%k)+abs(k/2-n/k)h,*FROM(SELECT
number n,len(@)*2-1k,*FROM spt_values)c)d
WHERE n<k*k and'P'=type
Ungolfed:
USE master
DECLARE
@y char='.',
@ varchar(32) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1))+iif((n+1)%k=0,char(13),@y),'')
FROM
(
SELECT abs(k/2-n%k)+abs(k/2-n/k)h,*
FROM
(
SELECT number n,len(@)*2-1k,*
FROM spt_values
)c
WHERE n<k*k and'P'=type
)d
I had to make some changes to format the output in the online version.
Try it online
$endgroup$
add a comment |
$begingroup$
TSQL query, 200 bytes
In MS-SQL Server Management Studio press Ctrl-T before running this query, this will change the output to text.
This script is building up the output from left to right in one long "string", calculating the value to put in each position, output starts with a line-break. The output is limited to 4096 characters.
Golfed:
USE master
DECLARE
@y char='.',
@ varchar(20) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1),@y)+iif((n+1)%k=0,char(13)),'')FROM(SELECT
abs(k/2-n%k)+abs(k/2-n/k)h,*FROM(SELECT
number n,len(@)*2-1k,*FROM spt_values)c)d
WHERE n<k*k and'P'=type
Ungolfed:
USE master
DECLARE
@y char='.',
@ varchar(32) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1))+iif((n+1)%k=0,char(13),@y),'')
FROM
(
SELECT abs(k/2-n%k)+abs(k/2-n/k)h,*
FROM
(
SELECT number n,len(@)*2-1k,*
FROM spt_values
)c
WHERE n<k*k and'P'=type
)d
I had to make some changes to format the output in the online version.
Try it online
$endgroup$
add a comment |
$begingroup$
TSQL query, 200 bytes
In MS-SQL Server Management Studio press Ctrl-T before running this query, this will change the output to text.
This script is building up the output from left to right in one long "string", calculating the value to put in each position, output starts with a line-break. The output is limited to 4096 characters.
Golfed:
USE master
DECLARE
@y char='.',
@ varchar(20) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1),@y)+iif((n+1)%k=0,char(13)),'')FROM(SELECT
abs(k/2-n%k)+abs(k/2-n/k)h,*FROM(SELECT
number n,len(@)*2-1k,*FROM spt_values)c)d
WHERE n<k*k and'P'=type
Ungolfed:
USE master
DECLARE
@y char='.',
@ varchar(32) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1))+iif((n+1)%k=0,char(13),@y),'')
FROM
(
SELECT abs(k/2-n%k)+abs(k/2-n/k)h,*
FROM
(
SELECT number n,len(@)*2-1k,*
FROM spt_values
)c
WHERE n<k*k and'P'=type
)d
I had to make some changes to format the output in the online version.
Try it online
$endgroup$
TSQL query, 200 bytes
In MS-SQL Server Management Studio press Ctrl-T before running this query, this will change the output to text.
This script is building up the output from left to right in one long "string", calculating the value to put in each position, output starts with a line-break. The output is limited to 4096 characters.
Golfed:
USE master
DECLARE
@y char='.',
@ varchar(20) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1),@y)+iif((n+1)%k=0,char(13)),'')FROM(SELECT
abs(k/2-n%k)+abs(k/2-n/k)h,*FROM(SELECT
number n,len(@)*2-1k,*FROM spt_values)c)d
WHERE n<k*k and'P'=type
Ungolfed:
USE master
DECLARE
@y char='.',
@ varchar(32) = 'abcd'
SELECT
string_agg(iif(h>k/2,@y,substring(@,h+1,1))+iif((n+1)%k=0,char(13),@y),'')
FROM
(
SELECT abs(k/2-n%k)+abs(k/2-n/k)h,*
FROM
(
SELECT number n,len(@)*2-1k,*
FROM spt_values
)c
WHERE n<k*k and'P'=type
)d
I had to make some changes to format the output in the online version.
Try it online
edited 4 hours ago
answered 11 hours ago
t-clausen.dkt-clausen.dk
2,024314
2,024314
add a comment |
add a comment |
$begingroup$
JavaScript (Node.js), 143 bytes
(s,c)=>q=Math.abs;m=(l=s.length*4-3)-1;for(i=j=0;j<l/2;(i=(++i)%l)?0:++j)p=s[q(i-m/2)/2+q(j-m/4)];process.stdout.write((i?"":"n")+(p?
p:c))
Try it online!
A bit more thinkering would lead to calculating in terms of a one-dimensional array, and less bytes.
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 143 bytes
(s,c)=>q=Math.abs;m=(l=s.length*4-3)-1;for(i=j=0;j<l/2;(i=(++i)%l)?0:++j)p=s[q(i-m/2)/2+q(j-m/4)];process.stdout.write((i?"":"n")+(p?
p:c))
Try it online!
A bit more thinkering would lead to calculating in terms of a one-dimensional array, and less bytes.
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 143 bytes
(s,c)=>q=Math.abs;m=(l=s.length*4-3)-1;for(i=j=0;j<l/2;(i=(++i)%l)?0:++j)p=s[q(i-m/2)/2+q(j-m/4)];process.stdout.write((i?"":"n")+(p?
p:c))
Try it online!
A bit more thinkering would lead to calculating in terms of a one-dimensional array, and less bytes.
$endgroup$
JavaScript (Node.js), 143 bytes
(s,c)=>q=Math.abs;m=(l=s.length*4-3)-1;for(i=j=0;j<l/2;(i=(++i)%l)?0:++j)p=s[q(i-m/2)/2+q(j-m/4)];process.stdout.write((i?"":"n")+(p?
p:c))
Try it online!
A bit more thinkering would lead to calculating in terms of a one-dimensional array, and less bytes.
answered 3 hours ago
Igor SowinskiIgor Sowinski
191
191
add a comment |
add a comment |
$begingroup$
Perl 6, 79 bytes
->cmap ,g .[^*X+(^$_,)]o*.comb
my&g=.[$_-1...0...$_-1]
Try it online!
Anonymous codeblock that takes input curried (like f(char)(string)
) and returns a list of strings. I think a different approach would be shorter.
$endgroup$
add a comment |
$begingroup$
Perl 6, 79 bytes
->cmap ,g .[^*X+(^$_,)]o*.comb
my&g=.[$_-1...0...$_-1]
Try it online!
Anonymous codeblock that takes input curried (like f(char)(string)
) and returns a list of strings. I think a different approach would be shorter.
$endgroup$
add a comment |
$begingroup$
Perl 6, 79 bytes
->cmap ,g .[^*X+(^$_,)]o*.comb
my&g=.[$_-1...0...$_-1]
Try it online!
Anonymous codeblock that takes input curried (like f(char)(string)
) and returns a list of strings. I think a different approach would be shorter.
$endgroup$
Perl 6, 79 bytes
->cmap ,g .[^*X+(^$_,)]o*.comb
my&g=.[$_-1...0...$_-1]
Try it online!
Anonymous codeblock that takes input curried (like f(char)(string)
) and returns a list of strings. I think a different approach would be shorter.
answered 46 mins ago
Jo KingJo King
25.6k362129
25.6k362129
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%2f182212%2flay-out-the-carpet%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$
Can the string contain spaces?
$endgroup$
– Emigna
yesterday
1
$begingroup$
@Emigna Yes, all printable ASCII (unicode range [32,126]) are valid input-characters.
$endgroup$
– Kevin Cruijssen
yesterday
1
$begingroup$
This becomes wonderful to debug if you use characters that visually look like a single character, e.g.
()()()
.$endgroup$
– Filip Haglund
yesterday
$begingroup$
What should happen if $s$ is empty?
$endgroup$
– Solomon Ucko
yesterday
$begingroup$
@SolomonUcko From the rules section: "Input-string and character are guaranteed to be non-empty" :)
$endgroup$
– Kevin Cruijssen
yesterday