Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/ABC-problem/F-Sharp/abc-problem-1.fs
Normal file
30
Task/ABC-problem/F-Sharp/abc-problem-1.fs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
let rec spell_word_with blocks w =
|
||||
let rec look_for_right_candidate candidates noCandidates c rest =
|
||||
match candidates with
|
||||
| [] -> false
|
||||
| c0::cc ->
|
||||
if spell_word_with (cc@noCandidates) rest then true
|
||||
else look_for_right_candidate cc (c0::noCandidates) c rest
|
||||
|
||||
match w with
|
||||
| "" -> true
|
||||
| w ->
|
||||
let c = w.[0]
|
||||
let rest = w.Substring(1)
|
||||
let (candidates, noCandidates) = List.partition(fun (c1,c2) -> c = c1 || c = c2) blocks
|
||||
look_for_right_candidate candidates noCandidates c rest
|
||||
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
let default_blocks = "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM"
|
||||
let blocks =
|
||||
(if argv.Length > 0 then argv.[0] else default_blocks).Split()
|
||||
|> List.ofArray
|
||||
|> List.map(fun s -> s.ToUpper())
|
||||
|> List.map(fun s2 -> s2.[0], s2.[1])
|
||||
let words =
|
||||
(if argv.Length > 0 then List.ofArray(argv).Tail else [])
|
||||
|> List.map(fun s -> s.ToUpper())
|
||||
|
||||
List.iter (fun w -> printfn "Using the blocks we can make the word '%s': %b" w (spell_word_with blocks w)) words
|
||||
0
|
||||
40
Task/ABC-problem/F-Sharp/abc-problem-2.fs
Normal file
40
Task/ABC-problem/F-Sharp/abc-problem-2.fs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
let blocks = [
|
||||
('B', 'O'); ('X', 'K'); ('D', 'Q'); ('C', 'P');
|
||||
('N', 'A'); ('G', 'T'); ('R', 'E'); ('T', 'G');
|
||||
('Q', 'D'); ('F', 'S'); ('J', 'W'); ('H', 'U');
|
||||
('V', 'I'); ('A', 'N'); ('O', 'B'); ('E', 'R');
|
||||
('F', 'S'); ('L', 'Y'); ('P', 'C'); ('Z', 'M');
|
||||
]
|
||||
|
||||
let find_letter blocks c =
|
||||
let found, remaining =
|
||||
List.partition (fun (c1, c2) -> c1 = c || c2 = c) blocks
|
||||
in
|
||||
match found with
|
||||
| _ :: res -> Some (res @ remaining)
|
||||
| _ -> None
|
||||
|
||||
let can_make_word w =
|
||||
let n = String.length w in
|
||||
let rec aux i _blocks =
|
||||
if i >= n then true else
|
||||
match find_letter _blocks w.[i] with
|
||||
| None -> false
|
||||
| Some rem_blocks ->
|
||||
aux (i+1) rem_blocks
|
||||
in
|
||||
aux 0 blocks
|
||||
|
||||
let test label f (word, should) =
|
||||
printfn "- %s %s = %A (should: %A)" label word (f word) should
|
||||
|
||||
let () =
|
||||
List.iter (test "can make word" can_make_word) [
|
||||
"A", true;
|
||||
"BARK", true;
|
||||
"BOOK", false;
|
||||
"TREAT", true;
|
||||
"COMMON", false;
|
||||
"SQUAD", true;
|
||||
"CONFUSE", true;
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue