Crates.io | anagram |
lib.rs | anagram |
version | 0.4.0 |
source | src |
created_at | 2021-02-25 22:28:03.181514 |
updated_at | 2021-03-17 18:00:01.569709 |
description | A collection of anagram utility functions |
homepage | https://github.com/terror/anagram |
repository | https://github.com/terror/anagram |
max_upload_size | |
id | 360723 |
size | 11,131 |
A collection of anagram utility functions
You can install this crate by adding it to your Cargo.toml file
anagram = "0.3.0"
use anagram::{count, get_next, is_anagram, occurences};
fn main() {
// count how many anagrams can be formed from a given word
let anagram_count = count("ordeals");
assert_eq!(anagram_count, 5040);
// count the number of occurences of an anagram in a given word
let occur = occurences("helloworldhello", "ll");
assert_eq!(occur, 2);
// check if a word is an anagram of another word
let ok = is_anagram("rustiscool", "oolcsistru");
assert_eq!(ok, true);
// get the next lexicographically greater anagram
let next = get_next("abcdefg");
assert_eq!(next, "abcdegf");
// get all anagrams of a word
let mut word: String = String::from("abc");
for _ in 0..count(&word) {
// get next anagram
word = get_next(&word);
println!("{}", word);
}
}