tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
9
Task/Reverse-a-string/OCaml/reverse-a-string-1.ocaml
Normal file
9
Task/Reverse-a-string/OCaml/reverse-a-string-1.ocaml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let rev_string str =
|
||||
let len = String.length str in
|
||||
let res = String.create len in
|
||||
let last = len - 1 in
|
||||
for i = 0 to last do
|
||||
let j = last - i in
|
||||
res.[i] <- str.[j];
|
||||
done;
|
||||
(res)
|
||||
8
Task/Reverse-a-string/OCaml/reverse-a-string-2.ocaml
Normal file
8
Task/Reverse-a-string/OCaml/reverse-a-string-2.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let rev_string str =
|
||||
let last = String.length str - 1 in
|
||||
for i = 0 to last / 2 do
|
||||
let j = last - i in
|
||||
let c = str.[i] in
|
||||
str.[i] <- str.[j];
|
||||
str.[j] <- c;
|
||||
done
|
||||
4
Task/Reverse-a-string/OCaml/reverse-a-string-3.ocaml
Normal file
4
Task/Reverse-a-string/OCaml/reverse-a-string-3.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let rec revs strin list index =
|
||||
if List.length list = String.length strin
|
||||
then String.concat "" list
|
||||
else revs strin ((String.sub strin index 1)::list) (index+1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue