Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Balanced-brackets/Julia/balanced-brackets-1.julia
Normal file
16
Task/Balanced-brackets/Julia/balanced-brackets-1.julia
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Printf
|
||||
|
||||
function balancedbrackets(str::AbstractString)
|
||||
i = 0
|
||||
for c in str
|
||||
if c == '[' i += 1 elseif c == ']' i -=1 end
|
||||
if i < 0 return false end
|
||||
end
|
||||
return i == 0
|
||||
end
|
||||
|
||||
brackets(n::Integer) = join(shuffle(collect(Char, "[]" ^ n)))
|
||||
|
||||
for (test, pass) in map(x -> (x, balancedbrackets(x)), collect(brackets(i) for i = 0:8))
|
||||
@printf("%22s%10s\n", test, pass ? "pass" : "fail")
|
||||
end
|
||||
1
Task/Balanced-brackets/Julia/balanced-brackets-2.julia
Normal file
1
Task/Balanced-brackets/Julia/balanced-brackets-2.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
balancedbrackets(str::AbstractString) = foldl((x, y) -> x < 0 ? -1 : x + y, collect((x == '[') - (x == ']') for x in str), init = 0) == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue