Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/String-matching/OCaml/string-matching-1.ocaml
Normal file
6
Task/String-matching/OCaml/string-matching-1.ocaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let match1 s1 s2 =
|
||||
let len1 = String.length s1
|
||||
and len2 = String.length s2 in
|
||||
if len1 < len2 then false else
|
||||
let sub = String.sub s1 0 len2 in
|
||||
(sub = s2)
|
||||
10
Task/String-matching/OCaml/string-matching-2.ocaml
Normal file
10
Task/String-matching/OCaml/string-matching-2.ocaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let match2 s1 s2 =
|
||||
let len1 = String.length s1
|
||||
and len2 = String.length s2 in
|
||||
if len1 < len2 then false else
|
||||
let rec aux i =
|
||||
if i < 0 then false else
|
||||
let sub = String.sub s1 i len2 in
|
||||
if (sub = s2) then true else aux (pred i)
|
||||
in
|
||||
aux (len1 - len2)
|
||||
6
Task/String-matching/OCaml/string-matching-3.ocaml
Normal file
6
Task/String-matching/OCaml/string-matching-3.ocaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let match3 s1 s2 =
|
||||
let len1 = String.length s1
|
||||
and len2 = String.length s2 in
|
||||
if len1 < len2 then false else
|
||||
let sub = String.sub s1 (len1 - len2) len2 in
|
||||
(sub = s2)
|
||||
10
Task/String-matching/OCaml/string-matching-4.ocaml
Normal file
10
Task/String-matching/OCaml/string-matching-4.ocaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let match2_loc s1 s2 =
|
||||
let len1 = String.length s1
|
||||
and len2 = String.length s2 in
|
||||
if len1 < len2 then (false, -1) else
|
||||
let rec aux i =
|
||||
if i < 0 then (false, -1) else
|
||||
let sub = String.sub s1 i len2 in
|
||||
if (sub = s2) then (true, i) else aux (pred i)
|
||||
in
|
||||
aux (len1 - len2)
|
||||
12
Task/String-matching/OCaml/string-matching-5.ocaml
Normal file
12
Task/String-matching/OCaml/string-matching-5.ocaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let match2_num s1 s2 =
|
||||
let len1 = String.length s1
|
||||
and len2 = String.length s2 in
|
||||
if len1 < len2 then (false, 0) else
|
||||
let rec aux i n =
|
||||
if i < 0 then (n <> 0, n) else
|
||||
let sub = String.sub s1 i len2 in
|
||||
if (sub = s2)
|
||||
then aux (pred i) (succ n)
|
||||
else aux (pred i) (n)
|
||||
in
|
||||
aux (len1 - len2) 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue