User talk:Gerard Schildberger: Difference between revisions

Content added Content deleted
m (→‎De Bruijn sequence, a draft: a work in progress.)
m (elided a draft topic.)
Line 862: Line 862:


: Yuppers. &nbsp; It was just that. &nbsp; Thanks for the heads up. &nbsp; I'm trying to figure out just how that happened, I can see how I might have missed the 1<sup>st</sup> line, but not the 2<sup>nd</sup>. &nbsp; &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 18:00, 7 July 2019 (UTC)
: Yuppers. &nbsp; It was just that. &nbsp; Thanks for the heads up. &nbsp; I'm trying to figure out just how that happened, I can see how I might have missed the 1<sup>st</sup> line, but not the 2<sup>nd</sup>. &nbsp; &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 18:00, 7 July 2019 (UTC)


== De Bruijn sequence, a draft ==

De Bruijn sequence <---- formal Rosetta Code task name. It might (or should be) named '''De Bruijn sequences''', but I don't
know how that (the plural) might hamper the finding of that task.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

««draft task»»
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ (The above was munged up to not cause Rosetta Code consternations.)

The sequences are named after the Dutch mathematician &nbsp; Nicolaas Govert de Bruijn.


A note on Dutch capitalization: &nbsp; Nicolaas' last name is &nbsp; '''de Bruijn''', &nbsp; the '''de''' isn't normally capitalized unless
it is the first word in a sentence. &nbsp; Rosetta Code (more or less by default or fiat) requires the first word in the task name to be
capitalized.



In combinatorial mathematics, &nbsp; a &nbsp; '''de Bruijn sequence''' &nbsp; of order &nbsp; <big> ''n'' </big> &nbsp; on
a &nbsp; <big> size-''k'' </big> &nbsp; alphabet (computer science) &nbsp; <big> ''A'' </big> &nbsp; is a cyclic sequence in which every
possible &nbsp; <big> length-''n'' </big> &nbsp; string (computer science, formal theory) &nbsp; on &nbsp; <big> ''A'' </big> &nbsp; occurs
exactly once as a contiguous substring.
<!--
───────────────────────────────────────────────────────────────────────────────────────────────────────
Yeah, I know, it's a pretty big mouthful, bit it's what Wikipedia uses, so I went with that definition.
───────────────────────────────────────────────────────────────────────────────────────────────────────
!-->

Such a sequence is denoted by &nbsp; <big> ''B''(''k'', ''n'') </big> &nbsp; and has
length &nbsp; <big>''k''<sup>''n''</sup></big>, &nbsp; which is also the number of distinct substrings of
length &nbsp; <big>''n''</big> &nbsp; on &nbsp; <big>''A''</big>; &nbsp; &nbsp;
<br>de Bruijn sequences are therefore optimally short.

<!--
────────────────────────────────────────────────────────────────────────────────────────────────────────
Expressing the (below) equation with a <math> HTML tag causes it to "blow up" on Rosetta Code's version.
────────────────────────────────────────────────────────────────────────────────────────────────────────
!-->
There are:
<big><big><big>(k!)<sup>k<sup>(n-1)</sup></sup> &nbsp; <big><b>&divide;</b></big> &nbsp; k<sup>n</sup></big></big></big>
distinct de Bruijn sequences &nbsp; <big> ''B''(''k'', ''n''). </big>



For this Rosetta Code task, &nbsp; a de Bruijn sequence is to be generated that can be used to shorten a brute-force attack on
a &nbsp; [https://en.wikipedia.org/wiki/Personal_Identification_Number PIN]-like &nbsp; code lock that does not have an "enter"
key and accepts the last &nbsp; <big> ''n'' </big> &nbsp; digits entered.


Note: &nbsp; [https://en.wikipedia.org/wiki/Automated_teller_machine automated tell machines (ATMs)] &nbsp; used to work like
this, &nbsp; but their software has been updated to not allow a brute-force attack.


;Example:
A &nbsp; [https://en.wikipedia.org/wiki/digital_door_lock digital door lock] &nbsp; with a 4-digit code would
have ''B''&thinsp;(10,&nbsp;4) solutions, &nbsp; with a length of &nbsp; '''10,000''' &nbsp; (digits).

Therefore, only at most &nbsp; &nbsp; '''10,000 + 3''' &nbsp; &nbsp; (as the solutions are cyclic) &nbsp; presses are needed to
open the lock.

Trying all codes separately would require &nbsp; '''4 &times; 10,000''' &nbsp; or &nbsp; '''40,000''' &nbsp; presses.


;Task:
:* &nbsp; Generate a de Bruijn sequence for a 4-digit (decimal) PIN code.
:::* &nbsp; (There are many possible de Bruijn sequences that solve this task.)
:::* &nbsp; Show the first and last &nbsp; '''130''' &nbsp; one hundred digits of the de Bruijn sequence.
:::* &nbsp; Show the length of the de Bruijn sequence.
:* &nbsp; Verify that all four-digit (decimal) &nbsp; '''1,000''' &nbsp; PIN codes are contained within the de Bruijn sequence.
:::* &nbsp; 0000, 0001, 0002, 0003, &nbsp; ... &nbsp; 9996, 9997, 9998, 9999 &nbsp; (note the leading zeros).
:* &nbsp; Reverse the de Bruijn sequence.
:* &nbsp; Again, perform the (above) verification test.
:* &nbsp; Extract the 4,444<sup>th</sup> digit from the original de Bruijn sequence.
:::* &nbsp; Add &nbsp; '''1''' &nbsp; (unity) to that digit.
:::* &nbsp; Take the right-most digit of that sum.
:::* &nbsp; Replace the original digit with the above digit &nbsp; (in the de Bruijn sequence).
:::* &nbsp; Perform the verification test (again). &nbsp; There should be several PIN codes missing.


(The last requirement is to ensure that the verification tests performs correctly. &nbsp; The verification processes should list
any and all missing PIN codes.)

Show all output here, on this page.


;References:
:* &nbsp; Wikipedia entry: &nbsp; [https://en.wikipedia.org/wiki/De_Bruijn_sequence de Bruijn sequence].
<br><br>