Print a Wavy String Line-by-Line
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
Challenge
Write a program or function that takes in a string s
and integer n
as parameters. Your program should print (or return) the string when transformed as follows:
Starting in the top-left and moving down and to the right, write s
as a wave of height n
. Then, from top to bottom, combine each row as a string (without spaces).
Example
Given the string "WATERMELON" and a height of 3:
The wave should look like this:
W R O
A E M L N
T E
Then, combine the rows from top to bottom:
WRO
AEMLN
TE
So, your program should return the string "WROAEMLNTE"
Likewise, "WATERMELON" with height 4 should produce the following wave:
W E
A M L
T R O
E N
Your program should then return the string "WEAMLTROEN"
Rules
Input
Input can be taken in any reasonable format. The string can be in any case you prefer. You may assume that 0 < n <= s.length
Output
Output should consist only of the transformed string (whether returned or printed to STDOUT), plus any trailing newlines.
Scoring
This is code-golf, so shortest answer in bytes wins! Standard loopholes are not allowed.
Test Cases
Input Output
programmingpuzzles, 5 -> piermnlsomgzgapzru
codegolf, 3 -> cgoeofdl
elephant, 4 -> enlatehp
1234567, 3 -> 1524637
qwertyuiop, 1 -> qwertyuiop
code-golf string
add a comment |Â
up vote
8
down vote
favorite
Challenge
Write a program or function that takes in a string s
and integer n
as parameters. Your program should print (or return) the string when transformed as follows:
Starting in the top-left and moving down and to the right, write s
as a wave of height n
. Then, from top to bottom, combine each row as a string (without spaces).
Example
Given the string "WATERMELON" and a height of 3:
The wave should look like this:
W R O
A E M L N
T E
Then, combine the rows from top to bottom:
WRO
AEMLN
TE
So, your program should return the string "WROAEMLNTE"
Likewise, "WATERMELON" with height 4 should produce the following wave:
W E
A M L
T R O
E N
Your program should then return the string "WEAMLTROEN"
Rules
Input
Input can be taken in any reasonable format. The string can be in any case you prefer. You may assume that 0 < n <= s.length
Output
Output should consist only of the transformed string (whether returned or printed to STDOUT), plus any trailing newlines.
Scoring
This is code-golf, so shortest answer in bytes wins! Standard loopholes are not allowed.
Test Cases
Input Output
programmingpuzzles, 5 -> piermnlsomgzgapzru
codegolf, 3 -> cgoeofdl
elephant, 4 -> enlatehp
1234567, 3 -> 1524637
qwertyuiop, 1 -> qwertyuiop
code-golf string
Can we assumen
>1? Please clarify and if not add a test case
– Luis Mendo
8 mins ago
Note that at least three current answers fail forn
=1. You would have to notify the users if that case needs to be supported
– Luis Mendo
2 mins ago
You may assumen > 0
, butn=1
is a valid case. I will update the question now.
– Cowabunghole
2 mins ago
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Challenge
Write a program or function that takes in a string s
and integer n
as parameters. Your program should print (or return) the string when transformed as follows:
Starting in the top-left and moving down and to the right, write s
as a wave of height n
. Then, from top to bottom, combine each row as a string (without spaces).
Example
Given the string "WATERMELON" and a height of 3:
The wave should look like this:
W R O
A E M L N
T E
Then, combine the rows from top to bottom:
WRO
AEMLN
TE
So, your program should return the string "WROAEMLNTE"
Likewise, "WATERMELON" with height 4 should produce the following wave:
W E
A M L
T R O
E N
Your program should then return the string "WEAMLTROEN"
Rules
Input
Input can be taken in any reasonable format. The string can be in any case you prefer. You may assume that 0 < n <= s.length
Output
Output should consist only of the transformed string (whether returned or printed to STDOUT), plus any trailing newlines.
Scoring
This is code-golf, so shortest answer in bytes wins! Standard loopholes are not allowed.
Test Cases
Input Output
programmingpuzzles, 5 -> piermnlsomgzgapzru
codegolf, 3 -> cgoeofdl
elephant, 4 -> enlatehp
1234567, 3 -> 1524637
qwertyuiop, 1 -> qwertyuiop
code-golf string
Challenge
Write a program or function that takes in a string s
and integer n
as parameters. Your program should print (or return) the string when transformed as follows:
Starting in the top-left and moving down and to the right, write s
as a wave of height n
. Then, from top to bottom, combine each row as a string (without spaces).
Example
Given the string "WATERMELON" and a height of 3:
The wave should look like this:
W R O
A E M L N
T E
Then, combine the rows from top to bottom:
WRO
AEMLN
TE
So, your program should return the string "WROAEMLNTE"
Likewise, "WATERMELON" with height 4 should produce the following wave:
W E
A M L
T R O
E N
Your program should then return the string "WEAMLTROEN"
Rules
Input
Input can be taken in any reasonable format. The string can be in any case you prefer. You may assume that 0 < n <= s.length
Output
Output should consist only of the transformed string (whether returned or printed to STDOUT), plus any trailing newlines.
Scoring
This is code-golf, so shortest answer in bytes wins! Standard loopholes are not allowed.
Test Cases
Input Output
programmingpuzzles, 5 -> piermnlsomgzgapzru
codegolf, 3 -> cgoeofdl
elephant, 4 -> enlatehp
1234567, 3 -> 1524637
qwertyuiop, 1 -> qwertyuiop
code-golf string
code-golf string
edited 18 secs ago
asked 1 hour ago
Cowabunghole
548212
548212
Can we assumen
>1? Please clarify and if not add a test case
– Luis Mendo
8 mins ago
Note that at least three current answers fail forn
=1. You would have to notify the users if that case needs to be supported
– Luis Mendo
2 mins ago
You may assumen > 0
, butn=1
is a valid case. I will update the question now.
– Cowabunghole
2 mins ago
add a comment |Â
Can we assumen
>1? Please clarify and if not add a test case
– Luis Mendo
8 mins ago
Note that at least three current answers fail forn
=1. You would have to notify the users if that case needs to be supported
– Luis Mendo
2 mins ago
You may assumen > 0
, butn=1
is a valid case. I will update the question now.
– Cowabunghole
2 mins ago
Can we assume
n
>1? Please clarify and if not add a test case– Luis Mendo
8 mins ago
Can we assume
n
>1? Please clarify and if not add a test case– Luis Mendo
8 mins ago
Note that at least three current answers fail for
n
=1. You would have to notify the users if that case needs to be supported– Luis Mendo
2 mins ago
Note that at least three current answers fail for
n
=1. You would have to notify the users if that case needs to be supported– Luis Mendo
2 mins ago
You may assume
n > 0
, but n=1
is a valid case. I will update the question now.– Cowabunghole
2 mins ago
You may assume
n > 0
, but n=1
is a valid case. I will update the question now.– Cowabunghole
2 mins ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
1
down vote
J, 48 bytes
' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
Try it online!
Quick initial solution, will golf it (and explain) later.
Here's my slightly cleaned REPL session in the J console:
3-|i:3
0 1 2 3 2 1 0
f=.#@[.]-[::]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1
f=.#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1 0 1 2 3
f=.1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1
1 1
2 1
3 1
2 1
1 1
0 1
1 1
2 1
3 1
f=.(],.' ')#~1,.~#@[$[:}:]-[:|i:@]
f=.(' ',.])#~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
f=.' ',.]
f 'watermelon'
w
a
t
e
r
m
e
l
o
n
f=.(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w
a
t
e
r
m
e
l
o
n
f=.[:|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e
a m l
t r o
e n
'programmingpuzzles' f 5
p g
r n p
o i u
g m z s
r m z e
a l
f=.[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e a m l t r o e n
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
weamltroen
'watermelon' f 4
woalnteemr
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
'watermelon' f 3
wroaemlnte
'watermelon' f 4
weamltroen
'programmingpuzzles' f 5
piermnlsomgzgapzru
'codegolf' f 3
cgoeofdl
add a comment |Â
up vote
1
down vote
MATL, 12 bytes
Zv3L)yn:)2$S
Try it online! Or verify all test cases.
Explanation
Zv % Implicit input: number n. Symmetric range
% STACK: [1 2 3 4 5 4 3 2 1]
3L % Push [1 -1+1j]. When used as an index, this means 1:end-1
% STACK: [1 2 3 4 5 4 3 2 1], [1 -1+1j]
) % Index. Removes last element
% STACK: [1 2 3 4 5 4 3 2]
y % Implict input: string s. Duplicate from below
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 'programmingpuzzles'
n % Number of elements
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 18
: % Range
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], [1 2 3 ··· 17 18]
) % Index modularly
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2]
2$S % Two-input sort: stably sorts first input as given by the second
% STACK: 'piermnlsomgzgapzru'
% Implicit display
add a comment |Â
up vote
0
down vote
MBASIC, 146 bytes
1 INPUT S$,N:DIM C$(N):P=1:D=1:FOR I=1 TO LEN(S$):C$(P)=C$(P)+MID$(S$,I,1)
2 IF P+D>N OR P+D=0 THEN D=-D
3 P=P+D:NEXT:FOR I=1 TO N:PRINT C$(I);:NEXT
Output:
? programmingpuzzles, 5
piermnlsomgzgapzru
? codegolf, 3
cgoeofdl
? elephant, 4
enlatehp
? 1234567, 3
1524637
? WATERMELON, 4
WEAMLTROEN
add a comment |Â
up vote
0
down vote
Python 2, 119 108 98 bytes
lambda s,n:''.join(s[j]for i in range(n)for j in range(len(s))if 0in((j-i)%(2*n-2),(j+i)%(2*n-2)))
Try it online!
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
J, 48 bytes
' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
Try it online!
Quick initial solution, will golf it (and explain) later.
Here's my slightly cleaned REPL session in the J console:
3-|i:3
0 1 2 3 2 1 0
f=.#@[.]-[::]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1
f=.#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1 0 1 2 3
f=.1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1
1 1
2 1
3 1
2 1
1 1
0 1
1 1
2 1
3 1
f=.(],.' ')#~1,.~#@[$[:}:]-[:|i:@]
f=.(' ',.])#~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
f=.' ',.]
f 'watermelon'
w
a
t
e
r
m
e
l
o
n
f=.(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w
a
t
e
r
m
e
l
o
n
f=.[:|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e
a m l
t r o
e n
'programmingpuzzles' f 5
p g
r n p
o i u
g m z s
r m z e
a l
f=.[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e a m l t r o e n
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
weamltroen
'watermelon' f 4
woalnteemr
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
'watermelon' f 3
wroaemlnte
'watermelon' f 4
weamltroen
'programmingpuzzles' f 5
piermnlsomgzgapzru
'codegolf' f 3
cgoeofdl
add a comment |Â
up vote
1
down vote
J, 48 bytes
' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
Try it online!
Quick initial solution, will golf it (and explain) later.
Here's my slightly cleaned REPL session in the J console:
3-|i:3
0 1 2 3 2 1 0
f=.#@[.]-[::]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1
f=.#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1 0 1 2 3
f=.1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1
1 1
2 1
3 1
2 1
1 1
0 1
1 1
2 1
3 1
f=.(],.' ')#~1,.~#@[$[:}:]-[:|i:@]
f=.(' ',.])#~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
f=.' ',.]
f 'watermelon'
w
a
t
e
r
m
e
l
o
n
f=.(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w
a
t
e
r
m
e
l
o
n
f=.[:|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e
a m l
t r o
e n
'programmingpuzzles' f 5
p g
r n p
o i u
g m z s
r m z e
a l
f=.[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e a m l t r o e n
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
weamltroen
'watermelon' f 4
woalnteemr
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
'watermelon' f 3
wroaemlnte
'watermelon' f 4
weamltroen
'programmingpuzzles' f 5
piermnlsomgzgapzru
'codegolf' f 3
cgoeofdl
add a comment |Â
up vote
1
down vote
up vote
1
down vote
J, 48 bytes
' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
Try it online!
Quick initial solution, will golf it (and explain) later.
Here's my slightly cleaned REPL session in the J console:
3-|i:3
0 1 2 3 2 1 0
f=.#@[.]-[::]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1
f=.#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1 0 1 2 3
f=.1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1
1 1
2 1
3 1
2 1
1 1
0 1
1 1
2 1
3 1
f=.(],.' ')#~1,.~#@[$[:}:]-[:|i:@]
f=.(' ',.])#~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
f=.' ',.]
f 'watermelon'
w
a
t
e
r
m
e
l
o
n
f=.(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w
a
t
e
r
m
e
l
o
n
f=.[:|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e
a m l
t r o
e n
'programmingpuzzles' f 5
p g
r n p
o i u
g m z s
r m z e
a l
f=.[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e a m l t r o e n
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
weamltroen
'watermelon' f 4
woalnteemr
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
'watermelon' f 3
wroaemlnte
'watermelon' f 4
weamltroen
'programmingpuzzles' f 5
piermnlsomgzgapzru
'codegolf' f 3
cgoeofdl
J, 48 bytes
' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
Try it online!
Quick initial solution, will golf it (and explain) later.
Here's my slightly cleaned REPL session in the J console:
3-|i:3
0 1 2 3 2 1 0
f=.#@[.]-[::]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1
f=.#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1 2 3 2 1 0 1 2 3
f=.1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
0 1
1 1
2 1
3 1
2 1
1 1
0 1
1 1
2 1
3 1
f=.(],.' ')#~1,.~#@[$[:}:]-[:|i:@]
f=.(' ',.])#~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
f=.' ',.]
f 'watermelon'
w
a
t
e
r
m
e
l
o
n
f=.(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w
a
t
e
r
m
e
l
o
n
f=.[:|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e
a m l
t r o
e n
'programmingpuzzles' f 5
p g
r n p
o i u
g m z s
r m z e
a l
f=.[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
w e a m l t r o e n
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@]
'watermelon' f 3
weamltroen
'watermelon' f 4
woalnteemr
f=.' '-.~[:,@|:(' ',.[)#"1~1,.~#@[$[:}:]-[:|i:@<:@]
'watermelon' f 3
wroaemlnte
'watermelon' f 4
weamltroen
'programmingpuzzles' f 5
piermnlsomgzgapzru
'codegolf' f 3
cgoeofdl
edited 22 mins ago
answered 29 mins ago
Galen Ivanov
5,2821931
5,2821931
add a comment |Â
add a comment |Â
up vote
1
down vote
MATL, 12 bytes
Zv3L)yn:)2$S
Try it online! Or verify all test cases.
Explanation
Zv % Implicit input: number n. Symmetric range
% STACK: [1 2 3 4 5 4 3 2 1]
3L % Push [1 -1+1j]. When used as an index, this means 1:end-1
% STACK: [1 2 3 4 5 4 3 2 1], [1 -1+1j]
) % Index. Removes last element
% STACK: [1 2 3 4 5 4 3 2]
y % Implict input: string s. Duplicate from below
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 'programmingpuzzles'
n % Number of elements
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 18
: % Range
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], [1 2 3 ··· 17 18]
) % Index modularly
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2]
2$S % Two-input sort: stably sorts first input as given by the second
% STACK: 'piermnlsomgzgapzru'
% Implicit display
add a comment |Â
up vote
1
down vote
MATL, 12 bytes
Zv3L)yn:)2$S
Try it online! Or verify all test cases.
Explanation
Zv % Implicit input: number n. Symmetric range
% STACK: [1 2 3 4 5 4 3 2 1]
3L % Push [1 -1+1j]. When used as an index, this means 1:end-1
% STACK: [1 2 3 4 5 4 3 2 1], [1 -1+1j]
) % Index. Removes last element
% STACK: [1 2 3 4 5 4 3 2]
y % Implict input: string s. Duplicate from below
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 'programmingpuzzles'
n % Number of elements
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 18
: % Range
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], [1 2 3 ··· 17 18]
) % Index modularly
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2]
2$S % Two-input sort: stably sorts first input as given by the second
% STACK: 'piermnlsomgzgapzru'
% Implicit display
add a comment |Â
up vote
1
down vote
up vote
1
down vote
MATL, 12 bytes
Zv3L)yn:)2$S
Try it online! Or verify all test cases.
Explanation
Zv % Implicit input: number n. Symmetric range
% STACK: [1 2 3 4 5 4 3 2 1]
3L % Push [1 -1+1j]. When used as an index, this means 1:end-1
% STACK: [1 2 3 4 5 4 3 2 1], [1 -1+1j]
) % Index. Removes last element
% STACK: [1 2 3 4 5 4 3 2]
y % Implict input: string s. Duplicate from below
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 'programmingpuzzles'
n % Number of elements
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 18
: % Range
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], [1 2 3 ··· 17 18]
) % Index modularly
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2]
2$S % Two-input sort: stably sorts first input as given by the second
% STACK: 'piermnlsomgzgapzru'
% Implicit display
MATL, 12 bytes
Zv3L)yn:)2$S
Try it online! Or verify all test cases.
Explanation
Zv % Implicit input: number n. Symmetric range
% STACK: [1 2 3 4 5 4 3 2 1]
3L % Push [1 -1+1j]. When used as an index, this means 1:end-1
% STACK: [1 2 3 4 5 4 3 2 1], [1 -1+1j]
) % Index. Removes last element
% STACK: [1 2 3 4 5 4 3 2]
y % Implict input: string s. Duplicate from below
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 'programmingpuzzles'
n % Number of elements
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], 18
: % Range
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2], [1 2 3 ··· 17 18]
) % Index modularly
% STACK: 'programmingpuzzles', [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2]
2$S % Two-input sort: stably sorts first input as given by the second
% STACK: 'piermnlsomgzgapzru'
% Implicit display
edited 15 mins ago
answered 20 mins ago


Luis Mendo
73.1k885286
73.1k885286
add a comment |Â
add a comment |Â
up vote
0
down vote
MBASIC, 146 bytes
1 INPUT S$,N:DIM C$(N):P=1:D=1:FOR I=1 TO LEN(S$):C$(P)=C$(P)+MID$(S$,I,1)
2 IF P+D>N OR P+D=0 THEN D=-D
3 P=P+D:NEXT:FOR I=1 TO N:PRINT C$(I);:NEXT
Output:
? programmingpuzzles, 5
piermnlsomgzgapzru
? codegolf, 3
cgoeofdl
? elephant, 4
enlatehp
? 1234567, 3
1524637
? WATERMELON, 4
WEAMLTROEN
add a comment |Â
up vote
0
down vote
MBASIC, 146 bytes
1 INPUT S$,N:DIM C$(N):P=1:D=1:FOR I=1 TO LEN(S$):C$(P)=C$(P)+MID$(S$,I,1)
2 IF P+D>N OR P+D=0 THEN D=-D
3 P=P+D:NEXT:FOR I=1 TO N:PRINT C$(I);:NEXT
Output:
? programmingpuzzles, 5
piermnlsomgzgapzru
? codegolf, 3
cgoeofdl
? elephant, 4
enlatehp
? 1234567, 3
1524637
? WATERMELON, 4
WEAMLTROEN
add a comment |Â
up vote
0
down vote
up vote
0
down vote
MBASIC, 146 bytes
1 INPUT S$,N:DIM C$(N):P=1:D=1:FOR I=1 TO LEN(S$):C$(P)=C$(P)+MID$(S$,I,1)
2 IF P+D>N OR P+D=0 THEN D=-D
3 P=P+D:NEXT:FOR I=1 TO N:PRINT C$(I);:NEXT
Output:
? programmingpuzzles, 5
piermnlsomgzgapzru
? codegolf, 3
cgoeofdl
? elephant, 4
enlatehp
? 1234567, 3
1524637
? WATERMELON, 4
WEAMLTROEN
MBASIC, 146 bytes
1 INPUT S$,N:DIM C$(N):P=1:D=1:FOR I=1 TO LEN(S$):C$(P)=C$(P)+MID$(S$,I,1)
2 IF P+D>N OR P+D=0 THEN D=-D
3 P=P+D:NEXT:FOR I=1 TO N:PRINT C$(I);:NEXT
Output:
? programmingpuzzles, 5
piermnlsomgzgapzru
? codegolf, 3
cgoeofdl
? elephant, 4
enlatehp
? 1234567, 3
1524637
? WATERMELON, 4
WEAMLTROEN
answered 16 mins ago
wooshinyobject
714
714
add a comment |Â
add a comment |Â
up vote
0
down vote
Python 2, 119 108 98 bytes
lambda s,n:''.join(s[j]for i in range(n)for j in range(len(s))if 0in((j-i)%(2*n-2),(j+i)%(2*n-2)))
Try it online!
add a comment |Â
up vote
0
down vote
Python 2, 119 108 98 bytes
lambda s,n:''.join(s[j]for i in range(n)for j in range(len(s))if 0in((j-i)%(2*n-2),(j+i)%(2*n-2)))
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Python 2, 119 108 98 bytes
lambda s,n:''.join(s[j]for i in range(n)for j in range(len(s))if 0in((j-i)%(2*n-2),(j+i)%(2*n-2)))
Try it online!
Python 2, 119 108 98 bytes
lambda s,n:''.join(s[j]for i in range(n)for j in range(len(s))if 0in((j-i)%(2*n-2),(j+i)%(2*n-2)))
Try it online!
edited 10 mins ago
answered 20 mins ago


TFeld
12.6k2835
12.6k2835
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174116%2fprint-a-wavy-string-line-by-line%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Can we assume
n
>1? Please clarify and if not add a test case– Luis Mendo
8 mins ago
Note that at least three current answers fail for
n
=1. You would have to notify the users if that case needs to be supported– Luis Mendo
2 mins ago
You may assume
n > 0
, butn=1
is a valid case. I will update the question now.– Cowabunghole
2 mins ago