RosettaCodeData/Task/ABC-problem/V-(Vlang)/abc-problem.v

29 lines
773 B
Coq
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
const blocks = ["BO","XK","DQ","CP","NA","GT","RE","TG","QD","FS",
"JW","HU","VI","AN","OB","ER","FS","LY","PC","ZM"]
const words = ["A", "BARK","BOOK","TREAT","COMMON","SQUAD","CONFUSE"]
2023-07-01 11:58:00 -04:00
fn main() {
2026-02-01 16:33:20 -08:00
for word in words {
println('>>> can_make_word("${word.to_upper()}"): ')
2026-04-30 12:34:36 -04:00
if check_word(word, blocks) == true { println("True") } else { println("False") }
2026-02-01 16:33:20 -08:00
}
2023-07-01 11:58:00 -04:00
}
fn check_word(word string, blocks []string) bool {
2026-02-01 16:33:20 -08:00
mut tblocks := blocks.clone()
mut found := false
for chr in word {
found = false
for idx, _ in tblocks {
if tblocks[idx].contains(chr.ascii_str()) == true {
2026-04-30 12:34:36 -04:00
tblocks[idx] =""
2026-02-01 16:33:20 -08:00
found = true
break
}
}
2026-04-30 12:34:36 -04:00
if found == false { return found }
2026-02-01 16:33:20 -08:00
}
return found
2023-07-01 11:58:00 -04:00
}