Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
let string_rev s =
let len = String.length s in
String.init len (fun i -> s.[len - 1 - i])
let () =
print_endline (string_rev "Hello world!")

View file

@ -0,0 +1,15 @@
let rev_bytes bs =
let last = Bytes.length bs - 1 in
for i = 0 to last / 2 do
let j = last - i in
let c = Bytes.get bs i in
Bytes.set bs i (Bytes.get bs j);
Bytes.set bs j c;
done
let () =
let s = Bytes.of_string "Hello World" in
rev_bytes s;
print_bytes s;
print_newline ();
;;

View file

@ -0,0 +1,9 @@
let rec revs_aux strin list index =
if List.length list = String.length strin
then String.concat "" list
else revs_aux strin ((String.sub strin index 1)::list) (index+1)
let revs s = revs_aux s [] 0
let () =
print_endline (revs "Hello World!")