Roll the carpetLay out the CarpetWind me a number snake!Spiral neighbourhoodsWrite the shortest code to match a tail-repeating string where one character falls off the head in each repetitionShortest code to dump a file into workable memoryFour steps to the left: vipers. Four steps to the right: a cliff. Don't die!Is it a lipogram?Turn a string into a windmillString Addition (Adding a Maximum of 9+9+9)The Three 'R's: Reverse, Reorder, RepeatVisit and exit an arrayOptimal Alphabet SteppingLay out the Carpet
Can I ask the recruiters in my resume to put the reason why I am rejected?
Perform and show arithmetic with LuaLaTeX
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Which country benefited the most from UN Security Council vetoes?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
How do I deal with an unproductive colleague in a small company?
What defenses are there against being summoned by the Gate spell?
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
dbcc cleantable batch size explanation
What is the word for reserving something for yourself before others do?
meaning of に in 本当に?
Theorems that impeded progress
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
How to format long polynomial?
Roll the carpet
Unable to deploy metadata from Partner Developer scratch org because of extra fields
Watching something be written to a file live with tail
Why does Kotter return in Welcome Back Kotter?
How old can references or sources in a thesis be?
Alternative to sending password over mail?
Rock identification in KY
What does "Puller Prush Person" mean?
Could an aircraft fly or hover using only jets of compressed air?
Do I have a twin with permutated remainders?
Roll the carpet
Lay out the CarpetWind me a number snake!Spiral neighbourhoodsWrite the shortest code to match a tail-repeating string where one character falls off the head in each repetitionShortest code to dump a file into workable memoryFour steps to the left: vipers. Four steps to the right: a cliff. Don't die!Is it a lipogram?Turn a string into a windmillString Addition (Adding a Maximum of 9+9+9)The Three 'R's: Reverse, Reorder, RepeatVisit and exit an arrayOptimal Alphabet SteppingLay out the Carpet
$begingroup$
This question is inspired by Kevin Cruijssen's question.
Now that the carpet is laid out, we want to roll it. Your task is to write a program that takes a string and returns a spiral made from this string (representing a rolled carpet viewed from the side).
The procedure for one step of rolling the carpet is the following. There is an example to illustrate what I mean. Notice that the example starts with a partially rolled carpet for better understanding:
ac
rpet
- separate the "head" from the "tail" of the carpet: the head is what has been rolled so far, the tail is what remains to be rolled.
Head: ac Tail:
rp et
- Rotate the head 90°, clockwise.
Rotated head: ra Tail (unchanged):
pc et
- if the width of the new head (here
2
) is less or equal than the length of the tail (here2
)- then, put it on top of the tail
- else, the carpet (as it was at the begining of the step) was rolled
New carpet: ra
pc
et
Repeat the procedure as many times as needed.
Two examples showing all steps of the carpet rolling:
carpet
c
arpet
ac
rpet
ra
pc
et
0123456789
0
123456789
10
23456789
21
30
456789
432
501
6789
Some precisions:
- You don't need to show all intermediate steps, only the rolled carpet (e.g. if you find a non-iterative way to compute the result, it's perfect). Also, you don't need to print any leading whitespace, in the examples above, I only show them to align stuff.
- Input is a String, a list/array of char
- Output is printed to stdout or to a file.
- Input is nice: the length is at least 1 char, and at most a constant sufficiently small so that it doesn't cause problems, but you can't use that constant in your program; the content of the string is only nice characters ([a-zA-Z0-9]), encoding at your preference.
- 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.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code.
- Also, add an explanation for your answer if you think it is needed.
code-golf string
$endgroup$
|
show 2 more comments
$begingroup$
This question is inspired by Kevin Cruijssen's question.
Now that the carpet is laid out, we want to roll it. Your task is to write a program that takes a string and returns a spiral made from this string (representing a rolled carpet viewed from the side).
The procedure for one step of rolling the carpet is the following. There is an example to illustrate what I mean. Notice that the example starts with a partially rolled carpet for better understanding:
ac
rpet
- separate the "head" from the "tail" of the carpet: the head is what has been rolled so far, the tail is what remains to be rolled.
Head: ac Tail:
rp et
- Rotate the head 90°, clockwise.
Rotated head: ra Tail (unchanged):
pc et
- if the width of the new head (here
2
) is less or equal than the length of the tail (here2
)- then, put it on top of the tail
- else, the carpet (as it was at the begining of the step) was rolled
New carpet: ra
pc
et
Repeat the procedure as many times as needed.
Two examples showing all steps of the carpet rolling:
carpet
c
arpet
ac
rpet
ra
pc
et
0123456789
0
123456789
10
23456789
21
30
456789
432
501
6789
Some precisions:
- You don't need to show all intermediate steps, only the rolled carpet (e.g. if you find a non-iterative way to compute the result, it's perfect). Also, you don't need to print any leading whitespace, in the examples above, I only show them to align stuff.
- Input is a String, a list/array of char
- Output is printed to stdout or to a file.
- Input is nice: the length is at least 1 char, and at most a constant sufficiently small so that it doesn't cause problems, but you can't use that constant in your program; the content of the string is only nice characters ([a-zA-Z0-9]), encoding at your preference.
- 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.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code.
- Also, add an explanation for your answer if you think it is needed.
code-golf string
$endgroup$
3
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
2
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
3
$begingroup$
Suggested test case:ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.
$endgroup$
– Sok
12 hours ago
$begingroup$
Where is the head on the secondcarpet
example, where nothing is rolled up?
$endgroup$
– Embodiment of Ignorance
10 hours ago
1
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago
|
show 2 more comments
$begingroup$
This question is inspired by Kevin Cruijssen's question.
Now that the carpet is laid out, we want to roll it. Your task is to write a program that takes a string and returns a spiral made from this string (representing a rolled carpet viewed from the side).
The procedure for one step of rolling the carpet is the following. There is an example to illustrate what I mean. Notice that the example starts with a partially rolled carpet for better understanding:
ac
rpet
- separate the "head" from the "tail" of the carpet: the head is what has been rolled so far, the tail is what remains to be rolled.
Head: ac Tail:
rp et
- Rotate the head 90°, clockwise.
Rotated head: ra Tail (unchanged):
pc et
- if the width of the new head (here
2
) is less or equal than the length of the tail (here2
)- then, put it on top of the tail
- else, the carpet (as it was at the begining of the step) was rolled
New carpet: ra
pc
et
Repeat the procedure as many times as needed.
Two examples showing all steps of the carpet rolling:
carpet
c
arpet
ac
rpet
ra
pc
et
0123456789
0
123456789
10
23456789
21
30
456789
432
501
6789
Some precisions:
- You don't need to show all intermediate steps, only the rolled carpet (e.g. if you find a non-iterative way to compute the result, it's perfect). Also, you don't need to print any leading whitespace, in the examples above, I only show them to align stuff.
- Input is a String, a list/array of char
- Output is printed to stdout or to a file.
- Input is nice: the length is at least 1 char, and at most a constant sufficiently small so that it doesn't cause problems, but you can't use that constant in your program; the content of the string is only nice characters ([a-zA-Z0-9]), encoding at your preference.
- 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.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code.
- Also, add an explanation for your answer if you think it is needed.
code-golf string
$endgroup$
This question is inspired by Kevin Cruijssen's question.
Now that the carpet is laid out, we want to roll it. Your task is to write a program that takes a string and returns a spiral made from this string (representing a rolled carpet viewed from the side).
The procedure for one step of rolling the carpet is the following. There is an example to illustrate what I mean. Notice that the example starts with a partially rolled carpet for better understanding:
ac
rpet
- separate the "head" from the "tail" of the carpet: the head is what has been rolled so far, the tail is what remains to be rolled.
Head: ac Tail:
rp et
- Rotate the head 90°, clockwise.
Rotated head: ra Tail (unchanged):
pc et
- if the width of the new head (here
2
) is less or equal than the length of the tail (here2
)- then, put it on top of the tail
- else, the carpet (as it was at the begining of the step) was rolled
New carpet: ra
pc
et
Repeat the procedure as many times as needed.
Two examples showing all steps of the carpet rolling:
carpet
c
arpet
ac
rpet
ra
pc
et
0123456789
0
123456789
10
23456789
21
30
456789
432
501
6789
Some precisions:
- You don't need to show all intermediate steps, only the rolled carpet (e.g. if you find a non-iterative way to compute the result, it's perfect). Also, you don't need to print any leading whitespace, in the examples above, I only show them to align stuff.
- Input is a String, a list/array of char
- Output is printed to stdout or to a file.
- Input is nice: the length is at least 1 char, and at most a constant sufficiently small so that it doesn't cause problems, but you can't use that constant in your program; the content of the string is only nice characters ([a-zA-Z0-9]), encoding at your preference.
- 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.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code.
- Also, add an explanation for your answer if you think it is needed.
code-golf string
code-golf string
edited 4 hours ago
Bromind
asked 13 hours ago
BromindBromind
1866
1866
3
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
2
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
3
$begingroup$
Suggested test case:ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.
$endgroup$
– Sok
12 hours ago
$begingroup$
Where is the head on the secondcarpet
example, where nothing is rolled up?
$endgroup$
– Embodiment of Ignorance
10 hours ago
1
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago
|
show 2 more comments
3
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
2
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
3
$begingroup$
Suggested test case:ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.
$endgroup$
– Sok
12 hours ago
$begingroup$
Where is the head on the secondcarpet
example, where nothing is rolled up?
$endgroup$
– Embodiment of Ignorance
10 hours ago
1
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago
3
3
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
2
2
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
3
3
$begingroup$
Suggested test case:
ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.$endgroup$
– Sok
12 hours ago
$begingroup$
Suggested test case:
ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.$endgroup$
– Sok
12 hours ago
$begingroup$
Where is the head on the second
carpet
example, where nothing is rolled up?$endgroup$
– Embodiment of Ignorance
10 hours ago
$begingroup$
Where is the head on the second
carpet
example, where nothing is rolled up?$endgroup$
– Embodiment of Ignorance
10 hours ago
1
1
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago
|
show 2 more comments
4 Answers
4
active
oldest
votes
$begingroup$
Pyth, 37 bytes
.U+j;bZ.WgleHJlhH,+_MChZ<eZJ>eZJ,]hQt
Try it online here, or verify all the test cases at once here.
.U+j;bZ.WgleHJlhH,+_MChZ<eZJ>eZJ,]hQtQ Implicit: Q=eval(input())
Trailing Q inferred
]hQ First character of Q, wrapped in an array
tQ All but the first character of Q
, 2-element array of the two previous results
This yields array with rolled carpet (as array of strings) followed by the tail
.W While condition function is truthy, execute inner function, with initial value of the above:
gleHJlhH Condition function, input H
JlhH Number of layers in the current rolled carpet, store in J
leH Lenth of the tail
g J Is the above greater than or equal to J?
,+_MChZ<eZJ>eZJ Inner function, input Z
_MChZ Rotate the current rolled carpet (transpose, then reverse each row)
+ <eZJ Append the first J characters of the tail as a new row
, Pair the above with...
>eZJ ... all but the first J characters of the tail - this is the new tail
.U+j;bZ Join the carpet roll on newlines and append the tail, implicit print
$endgroup$
add a comment |
$begingroup$
J, 73 bytes
[:(}:@[,:@:@[,:@:@[,:@:@[,improve this answer
$endgroup$
J, 73 bytes
[:(:@[,{:@[,])&>/[:((|:@|.@[,#@[.]);#@[.])&>/^:(<:&#&>/)^:_,:@,:@.;.
Try it online!
I plan to golf this further after work tonight.
answered 8 hours ago
JonahJonah
2,5611017
2,5611017
add a comment |
add a comment |
$begingroup$
R, 146 132 bytes
function(s)m=F[F]
while(m=rbind(t(m)[,F:0],s[1:F])
s=s[-1:-F]
length(s)>sum(F<-dim(m)))0
write(m[F:1,],1,F[1],,"")
cat(s,sep="")
Try it online!
Implements the carpet-rolling procedure. Takes input as a list of characters and prints to stdout.
Saved 14 bytes by finding a way to use a do-while
loop and initializing using F
.
function(s)
m=F[F] # logical(0); create an empty array (this gets automatically promoted to character(0) later
while( # do-while loop
m=rbind(t(m)[,F:0],s[1:F]) # rotate m counterclockwise and add the first F characters of s to the bottom
s=s[-1:-F] # remove those characters
length(s)>sum(F<-dim(m)))0 # while the number of characters remaining is greater than the sum of m's dimensions
write(m[F:1,],1,F[1],,"") # write the rolled portion write writes down the columns, we reverse each column
cat(s,sep="") # and write the remaining characters
$endgroup$
add a comment |
$begingroup$
R, 146 132 bytes
function(s)m=F[F]
while(m=rbind(t(m)[,F:0],s[1:F])
s=s[-1:-F]
length(s)>sum(F<-dim(m)))0
write(m[F:1,],1,F[1],,"")
cat(s,sep="")
Try it online!
Implements the carpet-rolling procedure. Takes input as a list of characters and prints to stdout.
Saved 14 bytes by finding a way to use a do-while
loop and initializing using F
.
function(s)
m=F[F] # logical(0); create an empty array (this gets automatically promoted to character(0) later
while( # do-while loop
m=rbind(t(m)[,F:0],s[1:F]) # rotate m counterclockwise and add the first F characters of s to the bottom
s=s[-1:-F] # remove those characters
length(s)>sum(F<-dim(m)))0 # while the number of characters remaining is greater than the sum of m's dimensions
write(m[F:1,],1,F[1],,"") # write the rolled portion write writes down the columns, we reverse each column
cat(s,sep="") # and write the remaining characters
$endgroup$
add a comment |
$begingroup$
R, 146 132 bytes
function(s)m=F[F]
while(m=rbind(t(m)[,F:0],s[1:F])
s=s[-1:-F]
length(s)>sum(F<-dim(m)))0
write(m[F:1,],1,F[1],,"")
cat(s,sep="")
Try it online!
Implements the carpet-rolling procedure. Takes input as a list of characters and prints to stdout.
Saved 14 bytes by finding a way to use a do-while
loop and initializing using F
.
function(s)
m=F[F] # logical(0); create an empty array (this gets automatically promoted to character(0) later
while( # do-while loop
m=rbind(t(m)[,F:0],s[1:F]) # rotate m counterclockwise and add the first F characters of s to the bottom
s=s[-1:-F] # remove those characters
length(s)>sum(F<-dim(m)))0 # while the number of characters remaining is greater than the sum of m's dimensions
write(m[F:1,],1,F[1],,"") # write the rolled portion write writes down the columns, we reverse each column
cat(s,sep="") # and write the remaining characters
$endgroup$
R, 146 132 bytes
function(s)m=F[F]
while(m=rbind(t(m)[,F:0],s[1:F])
s=s[-1:-F]
length(s)>sum(F<-dim(m)))0
write(m[F:1,],1,F[1],,"")
cat(s,sep="")
Try it online!
Implements the carpet-rolling procedure. Takes input as a list of characters and prints to stdout.
Saved 14 bytes by finding a way to use a do-while
loop and initializing using F
.
function(s)
m=F[F] # logical(0); create an empty array (this gets automatically promoted to character(0) later
while( # do-while loop
m=rbind(t(m)[,F:0],s[1:F]) # rotate m counterclockwise and add the first F characters of s to the bottom
s=s[-1:-F] # remove those characters
length(s)>sum(F<-dim(m)))0 # while the number of characters remaining is greater than the sum of m's dimensions
write(m[F:1,],1,F[1],,"") # write the rolled portion write writes down the columns, we reverse each column
cat(s,sep="") # and write the remaining characters
edited 11 hours ago
answered 12 hours ago
GiuseppeGiuseppe
17.6k31152
17.6k31152
add a comment |
add a comment |
$begingroup$
Jelly, 30 bytes
Seems overly long...
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ
Try it online!
How?
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ - Main Link: list of characters
Ḣ - pop and yield head
W - wrap in a list
, - pair with (the remaining list after Ḣ)
¿ - while...
$ - ...condition: last two links as a monad:
Ẉ - length of each
Ƒ - is invariant under:
Ṣ - sort
/ - ...do: reduce by:
ð ð - the enclosed dyadic chain -- i.e. f(head, tail):
Z - transpose
U - reverse each (giving a rotated head)
ɗ - last three links as a dyad:
¥ - last two links as a dyad:
L - length (i.e. number of rows in current roll)
@ - with swapped arguments:
s - split (the tail) into chunks of that length
© - (copy to register for later)
Ḣ - pop and yield head (Note register "copy" is altered too)
W - wrap in a list
; - concatenate (the rotated head with the first chunk of the tail)
¤ - nilad followed by link(s) as a nilad:
® - recall from register (other chunks of tail, or an empty list)
Ẏ - tighten (the chunks to a flat list)
, - pair (the concatenate result with the tightened chunks)
Ɗ - last three links as a monad:
Ḣ - pop and yield head
Y - join with newline characters
; - concatenate (the remaining tail)
- when running as a full program implicitly prints
$endgroup$
add a comment |
$begingroup$
Jelly, 30 bytes
Seems overly long...
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ
Try it online!
How?
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ - Main Link: list of characters
Ḣ - pop and yield head
W - wrap in a list
, - pair with (the remaining list after Ḣ)
¿ - while...
$ - ...condition: last two links as a monad:
Ẉ - length of each
Ƒ - is invariant under:
Ṣ - sort
/ - ...do: reduce by:
ð ð - the enclosed dyadic chain -- i.e. f(head, tail):
Z - transpose
U - reverse each (giving a rotated head)
ɗ - last three links as a dyad:
¥ - last two links as a dyad:
L - length (i.e. number of rows in current roll)
@ - with swapped arguments:
s - split (the tail) into chunks of that length
© - (copy to register for later)
Ḣ - pop and yield head (Note register "copy" is altered too)
W - wrap in a list
; - concatenate (the rotated head with the first chunk of the tail)
¤ - nilad followed by link(s) as a nilad:
® - recall from register (other chunks of tail, or an empty list)
Ẏ - tighten (the chunks to a flat list)
, - pair (the concatenate result with the tightened chunks)
Ɗ - last three links as a monad:
Ḣ - pop and yield head
Y - join with newline characters
; - concatenate (the remaining tail)
- when running as a full program implicitly prints
$endgroup$
add a comment |
$begingroup$
Jelly, 30 bytes
Seems overly long...
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ
Try it online!
How?
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ - Main Link: list of characters
Ḣ - pop and yield head
W - wrap in a list
, - pair with (the remaining list after Ḣ)
¿ - while...
$ - ...condition: last two links as a monad:
Ẉ - length of each
Ƒ - is invariant under:
Ṣ - sort
/ - ...do: reduce by:
ð ð - the enclosed dyadic chain -- i.e. f(head, tail):
Z - transpose
U - reverse each (giving a rotated head)
ɗ - last three links as a dyad:
¥ - last two links as a dyad:
L - length (i.e. number of rows in current roll)
@ - with swapped arguments:
s - split (the tail) into chunks of that length
© - (copy to register for later)
Ḣ - pop and yield head (Note register "copy" is altered too)
W - wrap in a list
; - concatenate (the rotated head with the first chunk of the tail)
¤ - nilad followed by link(s) as a nilad:
® - recall from register (other chunks of tail, or an empty list)
Ẏ - tighten (the chunks to a flat list)
, - pair (the concatenate result with the tightened chunks)
Ɗ - last three links as a monad:
Ḣ - pop and yield head
Y - join with newline characters
; - concatenate (the remaining tail)
- when running as a full program implicitly prints
$endgroup$
Jelly, 30 bytes
Seems overly long...
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ
Try it online!
How?
ḢW,ðZU;Ls@¥©ḢWɗ,®Ẏ¤ð/ẈṢƑ$¿ḢY;Ɗ - Main Link: list of characters
Ḣ - pop and yield head
W - wrap in a list
, - pair with (the remaining list after Ḣ)
¿ - while...
$ - ...condition: last two links as a monad:
Ẉ - length of each
Ƒ - is invariant under:
Ṣ - sort
/ - ...do: reduce by:
ð ð - the enclosed dyadic chain -- i.e. f(head, tail):
Z - transpose
U - reverse each (giving a rotated head)
ɗ - last three links as a dyad:
¥ - last two links as a dyad:
L - length (i.e. number of rows in current roll)
@ - with swapped arguments:
s - split (the tail) into chunks of that length
© - (copy to register for later)
Ḣ - pop and yield head (Note register "copy" is altered too)
W - wrap in a list
; - concatenate (the rotated head with the first chunk of the tail)
¤ - nilad followed by link(s) as a nilad:
® - recall from register (other chunks of tail, or an empty list)
Ẏ - tighten (the chunks to a flat list)
, - pair (the concatenate result with the tightened chunks)
Ɗ - last three links as a monad:
Ḣ - pop and yield head
Y - join with newline characters
; - concatenate (the remaining tail)
- when running as a full program implicitly prints
answered 7 hours ago
Jonathan AllanJonathan Allan
53.7k535173
53.7k535173
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%2f182727%2froll-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
3
$begingroup$
Closely related
$endgroup$
– Giuseppe
13 hours ago
2
$begingroup$
Also this one: codegolf.stackexchange.com/questions/125966/…, but none include the termination check.
$endgroup$
– Bromind
13 hours ago
3
$begingroup$
Suggested test case:
ProgrammingPuzzlesAndCodeGolf
- the final tail length greater than 1 tripped me up.$endgroup$
– Sok
12 hours ago
$begingroup$
Where is the head on the second
carpet
example, where nothing is rolled up?$endgroup$
– Embodiment of Ignorance
10 hours ago
1
$begingroup$
I think you've swapped the words "head" and "tail" here: "if the width of the new head [...] is greater or equal than the length of the tail [...]".
$endgroup$
– Erik the Outgolfer
5 hours ago