Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,33 +1,29 @@
|
|||
#![feature(core, unicode)]
|
||||
extern crate core;
|
||||
extern crate unicode;
|
||||
|
||||
use core::iter::repeat;
|
||||
use core::str::StrExt;
|
||||
use unicode::char::CharExt;
|
||||
use std::iter::repeat;
|
||||
|
||||
fn rec_can_make_word(index: usize, word: &str, blocks: &[&str], used: &mut[bool]) -> bool {
|
||||
let c = word.char_at(index).to_uppercase();
|
||||
for i in range(0, blocks.len()) {
|
||||
if !used[i] && blocks[i].chars().any(|s| s == c) {
|
||||
used[i] = true;
|
||||
if index == 0 || rec_can_make_word(index - 1, word, blocks, used) {
|
||||
return true;
|
||||
}
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
false
|
||||
let c = word.chars().nth(index).unwrap().to_uppercase().next().unwrap();
|
||||
for i in 0..blocks.len() {
|
||||
if !used[i] && blocks[i].chars().any(|s| s == c) {
|
||||
used[i] = true;
|
||||
if index == 0 || rec_can_make_word(index - 1, word, blocks, used) {
|
||||
return true;
|
||||
}
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
fn can_make_word(word: &str, blocks: &[&str]) -> bool {
|
||||
return rec_can_make_word(word.char_len() - 1, word, blocks, repeat(false).take(blocks.len()).collect::<Vec<_>>().as_mut_slice());
|
||||
return rec_can_make_word(word.chars().count() - 1, word, blocks,
|
||||
&mut repeat(false).take(blocks.len()).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let blocks = [("BO"), ("XK"), ("DQ"), ("CP"), ("NA"), ("GT"), ("RE"), ("TG"), ("QD"), ("FS"), ("JW"), ("HU"), ("VI"), ("AN"), ("OB"), ("ER"), ("FS"), ("LY"), ("PC"), ("ZM")];
|
||||
let words = ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"];
|
||||
for word in words.iter() {
|
||||
println!("{} -> {}", word, can_make_word(word.as_slice(), blocks.as_slice()))
|
||||
}
|
||||
let blocks = [("BO"), ("XK"), ("DQ"), ("CP"), ("NA"), ("GT"), ("RE"), ("TG"), ("QD"), ("FS"),
|
||||
("JW"), ("HU"), ("VI"), ("AN"), ("OB"), ("ER"), ("FS"), ("LY"), ("PC"), ("ZM")];
|
||||
let words = ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"];
|
||||
for word in &words {
|
||||
println!("{} -> {}", word, can_make_word(word, &blocks))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue