1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use std::io::{self, Write};
use std::iter;
fn make_passwords<W: Write>(patterns: &[Vec<u8>], buffer: &mut Vec<u8>, i: usize, writer: &mut W) {
if i == patterns.len() {
writer.write(&buffer).unwrap();
} else {
for c in patterns[i].iter() {
buffer[i] = *c;
make_passwords(patterns, buffer, i + 1, writer);
}
}
}
fn main() {
let range = |a, b| (a as u8..b as u8 + 1).collect::<Vec<_>>();
let patterns: Vec<Vec<u8>> = vec![
range('a', 'z').into_iter().chain(range('1', '9').into_iter()).collect(),
vec!('a' as u8, 'c' as u8),
range('a', 'z'),
range('a', 'z'),
range('a', 'z')
];
let mut buffer: Vec<u8> = vec!(0; patterns.len() + 1);
buffer[patterns.len()] = '\n' as u8;
let mut writer = io::BufWriter::new(io::stdout());
make_passwords(&patterns, &mut buffer, 0, &mut writer);
}
|