Series in Haskell
Given a string of digits, output all the contiguous substrings of length `n` in that string.
exercism fetch haskell series
Given a string of digits, output all the contiguous substrings of length
For example, the string "49142" has the following 3-digit series:
And the following 4-digit series:
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.
To complete this exercise you need to implement the function
that takes a text and returns the subsequences of digits with a
If it is your first time solving this exercise, it is recommended that you stick to the provided signature:
slices :: Int -> String -> [[Int]]
Later, it may be a good idea to revisit this problem and play with other data types and libraries:
ByteString, from package bytestring.
Sequence, from package containers.
Text, from package text.
Vector, from package vector.
The test suite was intentionally designed to accept almost any type signature that makes sense, so you are encouraged to find the one you think is the best.
For installation and learning resources, refer to the exercism help page.
Running the tests
To run the test suite, execute the following command:
If you get an error message like this...
No .cabal file found in directory
You are probably running an old stack version and need to upgrade it.
Otherwise, if you get an error message like this...
No compiler found, expected minor version match with... Try running "stack setup" to install the correct GHC...
Just do as it says and it will download and install the correct compiler version:
If you want to play with your solution in GHCi, just run the command:
Feedback, Issues, Pull Requests
The exercism/haskell repository on GitHub is the home for all of the Haskell exercises.
If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!
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.