Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Tree-datastructures/Julia/tree-datastructures.julia
Normal file
38
Task/Tree-datastructures/Julia/tree-datastructures.julia
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const nesttext = """
|
||||
RosettaCode
|
||||
rocks
|
||||
code
|
||||
comparison
|
||||
wiki
|
||||
mocks
|
||||
trolling
|
||||
"""
|
||||
|
||||
function nesttoindent(txt)
|
||||
ret = ""
|
||||
windent = gcd(length.([x.match for x in eachmatch(r"\s+", txt)]) .- 1)
|
||||
for lin in split(txt, "\n")
|
||||
ret *= isempty(lin) ? "\n" : isspace(lin[1]) ?
|
||||
replace(lin, r"\s+" => (s) -> "$(length(s)÷windent) ") * "\n" :
|
||||
"0 " * lin * "\n"
|
||||
end
|
||||
return ret, " "^windent
|
||||
end
|
||||
|
||||
function indenttonest(txt, indenttext)
|
||||
ret = ""
|
||||
for lin in filter(x -> length(x) > 1, split(txt, "\n"))
|
||||
(num, name) = split(lin, r"\s+", limit=2)
|
||||
indentnum = parse(Int, num)
|
||||
ret *= indentnum == 0 ? name * "\n" : indenttext^indentnum * name * "\n"
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
indenttext, itext = nesttoindent(nesttext)
|
||||
restorednesttext = indenttonest(indenttext, itext)
|
||||
|
||||
println("Original:\n", nesttext, "\n")
|
||||
println("Indent form:\n", indenttext, "\n")
|
||||
println("Back to nest form:\n", restorednesttext, "\n")
|
||||
println("original == restored: ", strip(nesttext) == strip(restorednesttext))
|
||||
Loading…
Add table
Add a link
Reference in a new issue