Created
July 17, 2021 18:15
-
-
Save NickyMeuleman/d871f70c8d93e8039bced80e8f7e9a02 to your computer and use it in GitHub Desktop.
alphametics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let permutations = (0u8..10u8).permutations(letters.len()); | |
<!-- 105s --> | |
let possible_dicts: Vec<BTreeMap<char, u8>> = permutations | |
.filter_map(|permutation| { | |
let dict: BTreeMap<char, u8> = letters.iter().copied().zip(permutation).collect(); | |
if dict.iter().any(|(c, &n)| leading.contains(c) && n == 0) { | |
None | |
} else { | |
Some(dict) | |
} | |
}) | |
.collect(); | |
<!-- 250s + --> | |
// for permutation in permutations { | |
// let dict: BTreeMap<char, u8> = letters.iter().copied().zip(permutation).collect(); | |
// if dict.iter().any(|(c, &n)| leading.contains(c) && n == 0) { | |
// continue; | |
// } else { | |
// possible_dicts.push(dict); | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment