-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
let rec mklist n = | ||
if n > 0 then | ||
let h = Random.int 0 in | ||
let t = mklist (n - 1) in | ||
h :: t | ||
else [] | ||
|
||
and len (l: int list) = | ||
match l with | ||
[] -> 0 | ||
| _ :: t -> 1 + len t | ||
|
||
and append (l1: int list) (l2: int list) = | ||
match l1 with | ||
[] -> l2 | ||
| h :: t -> h :: (append t l2) | ||
|
||
let main () = | ||
let m = | ||
let rec nd' () = | ||
let _' = Random.int 0 in | ||
if _' >= 0 then _' else nd' () | ||
in nd' () | ||
in | ||
let n = | ||
let rec nd' () = | ||
let _' = Random.int 0 in | ||
if _' >= 0 then _' else nd' () | ||
in nd' () | ||
in | ||
let l1 = mklist m in | ||
let l2 = mklist n in | ||
let sum_length = len l1 + len l2 in | ||
let l = append l1 l2 in | ||
assert (len(l) = sum_length); | ||
(()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let rec mklist n = | ||
if n > 0 then | ||
let h = Random.int 0 in | ||
let t = mklist (n - 1) in | ||
h :: t | ||
else [] | ||
|
||
and _reverse (l: int list) (acc: int list) = | ||
match l with | ||
[] -> acc | ||
| h :: t -> _reverse t (h :: acc) | ||
|
||
and reverse (l: int list) = | ||
_reverse l [] | ||
|
||
and len (l: int list) = | ||
match l with | ||
[] -> 0 | ||
| _ :: t -> 1 + len t | ||
|
||
let main () = | ||
let n = | ||
let rec nd' () = | ||
let _' = Random.int 0 in | ||
if _' >= 0 then _' else nd' () | ||
in nd' () | ||
in | ||
let l = mklist n in | ||
let __t0 = len l in | ||
let rev_l = reverse l in | ||
let __t1 = len rev_l in | ||
assert (__t0 = __t1); | ||
let __t2 = 0 in | ||
(()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters