Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Amb/OCaml/amb-1.ocaml
Normal file
36
Task/Amb/OCaml/amb-1.ocaml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
let set_1 = ["the"; "that"; "a"]
|
||||
let set_2 = ["frog"; "elephant"; "thing"]
|
||||
let set_3 = ["walked"; "treaded"; "grows"]
|
||||
let set_4 = ["slowly"; "quickly"]
|
||||
|
||||
let combs ll =
|
||||
let rec aux acc = function
|
||||
| [] -> (List.map List.rev acc)
|
||||
| hd::tl ->
|
||||
let acc =
|
||||
List.fold_left
|
||||
(fun _ac l ->
|
||||
List.fold_left (fun _ac v -> (v::l)::_ac) _ac hd
|
||||
) [] acc
|
||||
in
|
||||
aux acc tl
|
||||
in
|
||||
aux [[]] ll
|
||||
|
||||
let last s = s.[pred(String.length s)]
|
||||
let joined a b = (last a = b.[0])
|
||||
|
||||
let rec test = function
|
||||
| a::b::tl -> (joined a b) && (test (b::tl))
|
||||
| _ -> true
|
||||
|
||||
let print_set set =
|
||||
List.iter (Printf.printf " %s") set;
|
||||
print_newline();
|
||||
;;
|
||||
|
||||
let () =
|
||||
let sets = combs [set_1; set_2; set_3; set_4] in
|
||||
let sets = List.filter test sets in
|
||||
List.iter print_set sets;
|
||||
;;
|
||||
51
Task/Amb/OCaml/amb-2.ocaml
Normal file
51
Task/Amb/OCaml/amb-2.ocaml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
let set_1 = [| "the"; "that"; "a" |]
|
||||
let set_2 = [| "frog"; "elephant"; "thing" |]
|
||||
let set_3 = [| "walked"; "treaded"; "grows" |]
|
||||
let set_4 = [| "slowly"; "quickly" |]
|
||||
|
||||
let comb_search p aa =
|
||||
let nx = Array.make (Array.length aa) 0 in
|
||||
let lx = Array.map Array.length aa in
|
||||
let la = Array.length aa in
|
||||
let rec loop() =
|
||||
let res = Array.mapi (fun i j -> aa.(i).(j)) nx in
|
||||
if p res then (res)
|
||||
else
|
||||
( nx.(0) <- nx.(0) + 1;
|
||||
if nx.(0) < lx.(0)
|
||||
then loop()
|
||||
else
|
||||
( nx.(0) <- 0;
|
||||
let rec roll n =
|
||||
if n >= la then raise Not_found
|
||||
else
|
||||
( nx.(n) <- nx.(n) + 1;
|
||||
if nx.(n) >= lx.(n)
|
||||
then ( nx.(n) <- 0; roll (n+1) )
|
||||
else loop()
|
||||
)
|
||||
in
|
||||
roll 1
|
||||
)
|
||||
)
|
||||
in
|
||||
loop()
|
||||
|
||||
let last s = s.[pred(String.length s)]
|
||||
let joined a b = (last a = b.[0])
|
||||
|
||||
let rec test = function
|
||||
| a::b::tl -> (joined a b) && (test (b::tl))
|
||||
| _ -> true
|
||||
|
||||
let test r = test(Array.to_list r)
|
||||
|
||||
let print_set set =
|
||||
Array.iter (Printf.printf " %s") set;
|
||||
print_newline();
|
||||
;;
|
||||
|
||||
let () =
|
||||
let result = comb_search test [| set_1; set_2; set_3; set_4 |] in
|
||||
print_set result;
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue