I want to create an iterator that, given parameters of
my $iter = genIterator( 4, 3 ); print while $_ = $iter->();
will produce the following sequence (scrunched and formatted to show the sequence) in that order.
0 00 000 0000 0001 0002 001 0010 0011 0012 002 0020 0021 0022 01 010 0100 0101 0102 011 0110 0111 0112 012 0120 0121 0122 02 020 0200 0201 0202 021 0210 0211 0212 022 0220 0221 0222 1 10 100 1000 1001 1002 101 1010 1011 1012 102 1020 1021 1022 11 110 1100 1101 1102 111 1110 1111 1112 112 1120 1121 1122 12 120 1200 1201 1202 121 1210 1211 1212 122 1220 1221 1222 2 20 200 2000 2001 2002 201 2010 2011 2012 202 2020 2021 2022 21 210 2100 2101 2102 211 2110 2111 2112 212 2120 2121 2122 22 220 2200 2201 2202 221 2210 2211 2212 222 2220 2221 2222
I can do it with a (non-tail) recursive generator, but the lists get very large very quickly and most of the time I only need the next one or two at any given time.
I can 'convert' that generator into an iterator using a thread as a coroutine, but I don't want that dependancy.
Ideally, this would work the same way as tye''s NextPermute(), in that it would take a ref to an array (or possibly a string) and modify it to produce the in the sequence.
After 3 days of trying wrap my brain around this, a reference to some C code, or even what this sequence is called (lexical something?), would help.
In reply to In need of a sequence iterator. by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |