Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Generic De Bruijn Sequence

by LanX (Saint)
on Apr 19, 2017 at 22:49 UTC ( [id://1188334]=note: print w/replies, xml ) Need Help??


in reply to Generic De Bruijn Sequence

Did you consult wikipedia or search for other algorithms?

Many sources recommend an algorithm from Frank Ruskey , easily found implemented in various languages, here one in Python De_Bruijn_sequence#Algorithm which is not too hard to be ported.

Besides: The minimal length k^n is proven to be always achievable.

Which consequently means at least your first result and hence your algorithm is wrong.

update
De Bruijn is supposed to be cyclic!

AAACCCBCCACBBCBACABCAABBBABAA

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Generic De Bruijn Sequence
by QM (Parson) on Apr 19, 2017 at 23:07 UTC
    De Bruijn is supposed to be cyclic AAACCCBCCACBBCBACABCAABBBABAA

    Yes. The last $n-1 chars overlap with the beginning. The debug prints show each permutation lined up with the output string, so you can see how the graph is traversed and the output constructed. I could have just used the last char of each permutation, and had a true De Bruijn output, but that didn't suit my needs.

    I found the Python code, but didn't like it because of the lack of explanation. To understand it, I have to trace code that does a lot of index math, instead of reading comments hinting at an algorithm that makes sense on a higher level. It's not far removed from pointer math and assembler code, so it doesn't seem very Pythonic, as they like to say.

    If nothing else, my code at least tries to say what it's doing. So the next guy can try to understand it, and not blindly accept it, nor need to walk through on paper to believe that it's correct.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      > . The last $n-1 chars overlap with the beginning
      > debruijn.pl 5 2 AAEEDECEBEADDCDBDACCBCABBA 123456789012345678901234567890

      I don't understand how $n=5 (Alphabet size according to your code) results in length 26 instead of 25.

      please explain°

      edit

      >  walk through on paper to believe that it's correct.

      Your user image shows Richard P. Feynman and you are questioning scientific reviews in mathematics? Ironic :)

      UPDATE

      ") did you mean $t-1 ?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        ") did you mean $t-1 ?
        Yes. In my original code, I used $n for both. But later realized I could split that into 2 parameters. I probably used $n here through that mistake.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

      > so it doesn't seem very Pythonic, as they like to say.

      seems to be a port of the ruby version which is pretty straight forward ported for a Perl hacker

      http://gist.github.com/jonelf/3423148

      update

      Basically it's a inductive solution building complex sequences from more primitive ones starting with (1,1).

      I'm sure porting to Perl, using longer var names and dumping part solutions would explain the idea.

      update

      Though finding the original article would be better.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re^2: Generic De Bruijn Sequence
by BrowserUk (Patriarch) on Apr 19, 2017 at 23:03 UTC
    De Bruijn is supposed to be cyclic! AAACCCBCCACBBCBACABCAABBBABAA

    Maybe, but practicality means it is far simpler and more efficient to repeat the end sequence than to wrap around.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
      Maybe in this case, but check the length of his results, either way they are inconsistent and hence wrong.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        but check the length of his results, either way they are inconsistent and hence wrong.

        I've only had need to explore DeBruijn with a binary alphabet, so I'll defer to your judgement.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
        In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-19 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found