-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved solution for smelodesousa/F5/5-brackets (#40)
Close learn-ocaml-community/teaching-feedback#1 Co-authored-by: zazed <[email protected]>
- Loading branch information
Showing
5 changed files
with
17 additions
and
22 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 |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
[ | ||
"Rui Barata", | ||
"[email protected]" | ||
], | ||
[ | ||
"Leonardo Santos", | ||
"[email protected]" | ||
] | ||
], | ||
"backward_exercises": [ | ||
|
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
let verify text accumulator = | ||
let clean_accumulator acc = | ||
match acc with | ||
| c1::c2::t -> if c1 = ')' && c2 = '(' then t else acc | ||
| c1::[] -> acc | ||
| [] -> acc in | ||
let rec verify_aux text accumulator = | ||
match text with | ||
| c::t when (c = '(' || c = ')') -> verify_aux t (clean_accumulator (c::accumulator)) | ||
| c::t when (c <> '(' || c <> ')') -> verify_aux t accumulator | ||
| [] -> accumulator in | ||
(verify_aux text accumulator) = [] | ||
let verify text = | ||
List.fold_left | ||
(fun acc c -> if acc < 0 then acc else match c with '(' -> acc + 1 | ')' -> acc - 1 | _ -> acc) | ||
0 text | ||
= 0 |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
let verify text accumulator = | ||
let verify text = | ||
failwith "Replace with your solution" |
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