Dividing a character vector into segments

I have the following vector Vec: ACGTTGCAand I would like to divide it into a nested vector in which at the i-th position there will be a subsegment of Veclength 4, starting from the i-th position Vec.

For example, Vec[(⍳¯3+⍴Vec)∘.+¯1+⍳4]returns:

ACGT
CGTT
GTTG
TTGC
TGCA

But the problem with the above output is that it is a character matrix, while I would like to get the following output:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”β”‚
β”‚β”‚ACGTβ”‚CGTTβ”‚GTTGβ”‚TTGCβ”‚TGCAβ”‚β”‚
β”‚β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

For the next line: the vec←'Hy, only testing segmenting vec into pieces of 4' correct result of what I'm looking for would be:

β”Œβ†’β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β”             β”‚
β”‚ β”‚Hy, β”‚ β”‚y, oβ”‚ β”‚, onβ”‚ β”‚ onlβ”‚ (and so on) β”‚
β”‚ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜             β”‚
β””βˆŠβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

In addition, is there a way to convert such a vector into a single vector in which subsequent lines will contain 4 characters?

Example: for a character symbol, the foobartestingresult is:

foob
ooba
obar
bart
arte
rtes
test
esti
stin
ting
+4
3

GNU APL, , Dyalog. :

      4 ,/ 'foobartesting'
 foob ooba obar bart arte rtes test esti stin ting
+2

: "split" (↓), , () . , , "" , , , , APL.

Dyalog APL v14.0/64, Intel Core i5 @1.60Ghz:

← 'foobartesting'

(4,/x) 9,3

(↓ 4 {⍡ [(0, ⍳-⍺-⍴⍡) ∘. + ⍳⍺]} x) 2.3

; , 10 000, 10 (7 0,7 ).

DALOG APL "" 1- 2- ; , APL.

+3

, . , :

vec←'Hy, only testing segmenting vec into pieces of 4'

, : -)

βŽ•ml←3

;-):

      display 4{⍺↑¨(0,⍳(⍴⍡)-⍺)β†“Β¨βŠ‚β΅}'ACGTTGCA'
β”Œβ†’β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”Œβ†’β”€β”€β”€β” β”‚
β”‚ β”‚ACGTβ”‚ β”‚CGTTβ”‚ β”‚GTTGβ”‚ β”‚TTGCβ”‚ β”‚TGCAβ”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”˜ β”‚
β””βˆŠβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0

All Articles