Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics

Dashboard
Notifications
Mark all as read
Challenges

Weave Strings Together

+3
−0

Given a list of strings(and optionally, their length) as input, weave the strings together.

Intro

Your goal is to mimic the WV operator in Pip. Take a list of strings and alternate between their characters like so:

hello,
world, → hwc,eoo,lrd,lle,od → hwceoolrdlleod
code

Effectively, you need to group the characters at each index, and join them into a single string.

The strings may have spaces.

No truncation should be done, and all the characters of each string must be used.

Test Cases

Without the outputs

["kino","cinema","movie"] → kcmiionnvoeimea
["code","golf"] → cgoodlef
["Hi","","There"] → HTihere
["Explanation"] → Explanation
["Dyalog APL","Cultivation","Orchard"] → DCOyuralclthoiagvr adAtPiLon

You check any other test cases with this program.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

3 comments

Ugh, the "strings may have spaces" and the way you don't pad the strings makes it unusually annoying. Quintec‭ 2 months ago

Can we take the strings as an array of characters? Shaggy‭ 2 months ago

@Shaggy yes, you can Razetime‭ 2 months ago

4 answers

+2
−0

Japt -P, 7 2 bytes

Õc

Takes input as character arrays. -5 bytes thanks to @Shaggy

Try it

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comments

Õc with the -P flag would work, taking the strings as character arrays. Shaggy‭ 2 months ago

@Shaggy cheers, thanks Quintec‭ 2 months ago

+2
−0

APL (Dyalog Unicode), 10 bytes

Full program. Prompts for list of strings from stdin.

0~⍨,⍉↑0,¨⎕

Try it online!

 prompt for list of strings

0,¨ prepend a zero to each

 convert to orthogonal matrix (increase rank at cost of depth), padding with 0s

 transpose

, ravel (flatten)

0~⍨ remove 0s

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

+1
−0

Haskell, 40 bytes

f((h:t):r)=h:f(r++[t])
f(_:r)=f r
f _=[]

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

+1
−0

JavaScript (Node.js), 53 bytes

f=(a,b=[],c=a.map(([a,...c])=>(b+=[a],c)))=>b&&b+f(c)

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!