Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
25
Task/Balanced-brackets/Ed/balanced-brackets.ed
Normal file
25
Task/Balanced-brackets/Ed/balanced-brackets.ed
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# by Artyom Bologov
|
||||
H
|
||||
# Remove all the non-bracket chars
|
||||
g/.*/s/[^][]//gp
|
||||
# Repeatedly remove all the simple matching brackets.
|
||||
# Add more lines to handle deeper nested expressions.
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/\[\]/s///g
|
||||
g/./s/.*/Not balanced!/
|
||||
g/^$/s/.*/Balanced!/
|
||||
,p
|
||||
Q
|
||||
41
Task/Balanced-brackets/Zig/balanced-brackets.zig
Normal file
41
Task/Balanced-brackets/Zig/balanced-brackets.zig
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
const std = @import("std");
|
||||
const print = std.debug.print;
|
||||
|
||||
const max_pairs = 256;
|
||||
|
||||
pub fn is_balanced(buf: []u8) bool {
|
||||
var count: usize = 0;
|
||||
for (buf) |ch| switch (ch) {
|
||||
'[' => count += 1,
|
||||
']' => {
|
||||
if (count == 0) return false;
|
||||
count -= 1;
|
||||
},
|
||||
else => return false,
|
||||
};
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
for (0..10) |n_pairs| {
|
||||
if (n_pairs > max_pairs)
|
||||
return error.MaximumNumberOfPairsExceded;
|
||||
|
||||
var buf: [2 * max_pairs]u8 = undefined;
|
||||
for (0..n_pairs) |i| buf[i] = '[';
|
||||
for (n_pairs..n_pairs * 2) |i| buf[i] = ']';
|
||||
|
||||
const rand = std.crypto.random;
|
||||
const len = n_pairs * 2;
|
||||
const reps = 2;
|
||||
for (0..len * reps) |i_rep| {
|
||||
const i = i_rep % len;
|
||||
const j = rand.int(usize) % len;
|
||||
const temp = buf[i];
|
||||
buf[i] = buf[j];
|
||||
buf[j] = temp;
|
||||
}
|
||||
const s = buf[0..len];
|
||||
print("'{s}': {}\n", .{ s, is_balanced(s) });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue