1

I'm working on something that could tell whether or not the given string is a valid de Bruijn sequence of order n

So I want to split the given string at every character into a list of size n Strings

Example : "011001100" order = 3

becomes {"011", "110", "100", "001", "110", "100"} Now I can easily check if the list contains one of the elements twice or more

I'm quite the newbie with haskell, I tried to do something myself but I don't know where to start. (if you have any other idea to do the given task i'm open to it)

Answering comment : What i've tried :

import Data.List

chunk :: Int -> [a] -> [[a]]
chunk _ [] = []
chunk n xs = first : chunk n rest where (first, rest) = splitAt n xs

Then I can get the list with:

print $ transpose $ chunk order sequence
  • 3
    What did you try yourself? How would you define the output for this function for an empty list, a list with 1, 2, 3 elements, and a solution for *n* elements in terms of *n-1* elements? – Willem Van Onsem May 03 '18 at 15:36
  • `take 3` is your friend. write a recursive function, or use `foldl` to produce the entire list. – 9000 May 03 '18 at 15:36
  • @WillemVanOnsem I've updated the question for your first interrogation. However I'm not sure I understood the other ones ? If you mean error handling related stuff I can manage that my self before passing the string. I'm also looking into take and foldl thank you – Mathis Panzani May 03 '18 at 16:09
  • Kudos for staying engaged and editing your question to include your code! It so happens that this question was already asked and answered on this site. You're welcome to peruse the linked entry, and ask any new questions as you get them. Welcome to Stack Overflow! – Will Ness May 03 '18 at 16:21
  • if the answers there are unsatisfactory, and you want to implement this function yourself by direct recursion instead of using other built-in functions for example (as a learning exercise, perhaps), ask a new question underscoring this requirement, and include any code you have, again (and always). – Will Ness May 03 '18 at 16:30

0 Answers0