RosettaCodeData/Task/ABC-problem/UTFool/abc-problem-1.utfool

28 lines
948 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

···
http://rosettacode.org/wiki/ABC_Problem
···
■ ABC
§ static
blocks⦂ StringBuffer " BO XK DQ CP NA GT RE TG QD FS
JW HU VI AN OB ER FS LY PC ZM"
▶ main
• args⦂ String[]
for each word in ["A", "BARK", "BOOK", "TREAT",
"COMMON", "SQUAD", "CONFUSE"]⦂ String
System.out.println "⸨word⸩: ⸨canMakeWord word⸩"
▶ canMakeWord⦂ boolean
• word⦂ String
solution⦂ boolean: word.isEmpty°
if no solution
i⦂ int: blocks.indexOf word.substring 0, 1
🔁 until solution or i < 0
i: i ÷ 3 × 3 · block index
block⦂ String: blocks.substring i, i + 3
blocks.delete i, i + 3 · remove block
solution: canMakeWord word.substring 1
blocks.insert i, block · restore block
i: blocks.indexOf (word.substring 0, 1), i + 3
return solution