Unslice a string
Python 2, 49 bytes
lambda l:`map(max,*[' '*n+s for n,s in l])`[2::5]
First, lines up the strings by padding their offsets with spaces (shown as underscores for clarity)
[[2, "CG"], [0, "PP"], [1, "PC"]]
__CG
PP
_PC
Then, uses map
to zip
and take the maximum of each column, which ignores the smaller values of spaces (the smallest printable character) and None
s where some strings were too short.
__CG
PP
_PC
PPCG
Finally, ''.join
to a string using the [2::5]
trick.
JavaScript (ES6), 61 bytes
a=>a.map(([o,s])=>[...s].map(c=>r[o++]=c),r=[])&&r.join``
Edit: Saved 4 bytes thanks to @edc65.
Perl, 25
Added +2 for -lp
Get the input from STDIN, e.g.
perl -lp slices.pl
2 CG
0 PP
1 PC
(Close with ^D or ^Z or whatever closes STDIN on your system)
slices.pl
:
/ /;$r|=v0 x$`.$'}{*_=r