De Bruijn sequences: Difference between revisions
→{{header|Perl 6}}: Randomize the sequence
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Rewrote, rearranged a bit, DRY, Deviate slightly from task spec.) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Randomize the sequence) |
||
Line 217:
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
Deviates very slightly from the task spec.
<lang perl6># Generate the sequence
Line 231:
}
}
$seq = $seq.comb.list.rotate((^10000).pick).join;
$seq ~= $seq.substr(0,3);
sub check ($seq) {
my %chk;
for ^($seq.chars) { %chk{$seq.substr( $_, 4 )}++ }
put 'Missing: ', (^9999).grep( { not %chk{ .fmt: '%04d' } } ).fmt: '%04d';
put 'Extra: ', %chk.grep( *.value > 1 )».key.sort.fmt: '%04d';
}
Line 253 ⟶ 256:
check $seq.flip;
put "\nReplacing the 4444th digit, ($digit) with { ($digit += 1) %= 10 }";
put "Incorrect 4 digit PINs in the revised sequence:";
$seq.substr-rw(4443,1) =
check $seq;</lang>
{{out|Sample output}}
<pre>de Bruijn sequence length: 10003
First 130 characters:
4558455945654566456745684569457545764577457845794585458645874588458945954596459745984599464647464846494655465646574658465946654666
Last 130 characters:
5445644574458445944654466446744684469447544764477447844794485448644874488448944954496449744984499454546454745484549455545564557455
Incorrect 4 digit PINs in this sequence:
Line 275 ⟶ 278:
Extra:
Replacing the 4444th digit, (
Incorrect 4 digit PINs in the revised sequence:
Missing:
Extra:
=={{header|REXX}}==
|