Problem 56180. Boustrophedon

Given a vector v and a positive integer n, return an m-by-n matrix containing the elements of v row-wise, alternating left-to-right and right-to-left ordering:
You can assume that the number of elements of v will be an integer multiple of n.
For example:
v = 1:12;
boustrophedon(v,4)
ans =
1 2 3 4
8 7 6 5
9 10 11 12
boustrophedon(v,6)
ans =
1 2 3 4 5 6
12 11 10 9 8 7
v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];
ans =
20 1 18 4 13
17 2 15 10 6
3 19 7 16 8
5 12 9 14 11
t = 'We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. hat to secure these rights, Governments are instituted among Men, deriving their just powe';
boustrophedon(t,30)
ans =
10×30 char array
'We hold these truths to be sel'
'rc era nem lla taht ,tnedive-f'
'eated equal, that they are end'
'rec htiw rotaerC rieht yb dewo'
'tain unalienable Rights, that '
' ytrebiL ,efiL era eseht gnoma'
'and the pursuit of Happiness. '
'oG ,sthgir eseht eruces ot tah'
'vernments are instituted among'
'ewop tsuj rieht gnivired ,neM '

Solution Stats

57.35% Correct | 42.65% Incorrect
Last Solution submitted on Jun 05, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers101

Suggested Problems

More from this Author12

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!