 # JaeHyoLee's solution

## to Series in the Lua Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

Given a string of digits, output all the contiguous substrings of length `n` in that string.

For example, the string "49142" has the following 3-digit series:

• 491
• 914
• 142

And the following 4-digit series:

• 4914
• 9142

And if you ask for a 6-digit series from a 5-digit string, you deserve whatever you get.

Note that these series are only required to occupy adjacent positions in the input; the digits need not be numerically consecutive.

## Running the tests

To run the tests, run the command `busted` from within the exercise directory.

## Further information

For more detailed information about the Lua track, including how to get help if you're having trouble, please visit the exercism.io Lua language page.

## Source

A subset of the Problem 8 at Project Euler http://projecteuler.net/problem=8

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### series_spec.lua

``````local series = require('series')

describe('series', function()
it('should generate 1 character series', function()
local result = {}
for s in series('abcde', 1) do
table.insert(result, s)
end
assert.same({ 'a', 'b', 'c', 'd', 'e' }, result)
end)

it('should generate multi-character series', function()
local result = {}
for s in series('hello', 3) do
table.insert(result, s)
end
assert.same({ 'hel', 'ell', 'llo' }, result)
end)

it('should generate one series when the series length equals the string length', function()
local result = {}
for s in series('exercism', 8) do
table.insert(result, s)
end
assert.same({ 'exercism' }, result)
end)

it('should return no series when the series length requested is longer than the string', function()
local result = {}
for s in series('1234', 5) do
table.insert(result, s)
end
assert.same({}, result)
end)
end)``````
``````return function (a, n)
return coroutine.wrap(function()
for i=1, #a-n+1 do
coroutine.yield(a:sub(i, i+n-1))
end
end)
end``````