Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2016 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/542af9ab0287019fac3429f285359bce to your computer and use it in GitHub Desktop.
Save anonymous/542af9ab0287019fac3429f285359bce to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![feature(str_char)]
fn to_word(mut n: u32) -> String{
let mut str = String::new();
for _ in 0..10{
let c = match n%5{
0 => 'A',
1 => 'B',
2 => 'C',
3 => 'D',
4 => 'E',
_ => unreachable!()
};
n /= 5;
str = format!("{}{}", c, str);
}
return str;
}
fn main(){
let mut c = 0;
'next_i: for i in 0..9765625 {
if i % (9765625 / 100) == 0 {
println!("{}%", i / (9765625 / 100));
}
let str = to_word(i);
if str.char_at(0) != 'E' && str.char_at(0) != 'A' {continue 'next_i;}
for l in 0..9{
if str.char_at(l) == str.char_at(l+1) {continue 'next_i;}
if str.char_at(l) == 'A' && str.char_at(l+1) == 'E' {continue 'next_i;}
if str.char_at(l) == 'E' && str.char_at(l+1) == 'A' {continue 'next_i;}
}
c += 1;
}
println!("{}", c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment