Initial Commit
This commit is contained in:
789 files changed
+149185
No files matched your search
@@ -0,0 +1,21 @@
|
||||
# An assertion says what failed in words of its own, in place of the condition,
|
||||
# and an `ensures` in a loop's block is checked at each pass's end.
|
||||
import std::io;
|
||||
|
||||
def balanced(lines: span<strview>): void {
|
||||
for line in lines {
|
||||
var depth := 0;
|
||||
ensures(depth == 0);
|
||||
for c in line {
|
||||
continue if c == ' ';
|
||||
depth += c == '(' ? 1 : c == ')' ? -1 : 0;
|
||||
asserts(depth >= 0, "A parenthesis closes one never opened.");
|
||||
}
|
||||
io::println($"{line} closes what it opens");
|
||||
}
|
||||
}
|
||||
|
||||
def main(): void {
|
||||
balanced(["(a)", "((b) c)"]);
|
||||
balanced(["(d))"]);
|
||||
}
|
||||
Reference in new issue
Block a user