An acrostic cipher is a way of embedding one message within another by taking the first (or last) word of each line. Given a string s, and a positive integer n, return a string containing the message you would get by taking the first word on each line, having written the message in s with n words on each line.
You do not need to worry about punctuation. A "word" is anything separated by a space. The input message will use only single spaces (and no line breaks or other whitespace). Similarly, the output message should use only single spaces between words.
Note that the number of words in s is not necessarily a multiple of n.
Also note that this problem can be solved more directly than using the method described above.
t = "This week's Cody challenge is designed to test an essential skill that's easy to have a problem with.";
acrostic(t,4)
ans =
"This is an easy problem"
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers120
Suggested Problems
-
46851 Solvers
-
Remove the small words from a list of words.
1560 Solvers
-
Project Euler: Problem 9, Pythagorean numbers
1385 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1265 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2147 Solvers
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!