Skip to content

Instantly share code, notes, and snippets.

@NoFishLikeIan
Created October 31, 2022 16:48
Show Gist options
  • Save NoFishLikeIan/ca81e3b566245d0498ffa0705416560d to your computer and use it in GitHub Desktop.
Save NoFishLikeIan/ca81e3b566245d0498ffa0705416560d to your computer and use it in GitHub Desktop.
"Pair"
function ↑(a::String, b::String)
a * '0' * b * a * '1' * b
end
"""
Unpair one step
"""
function ↓(p::String)
mid = length(p) ÷ 2
diff = findfirst(i -> p[i] != p[i + mid], 1:mid)
if p[diff] ∉ ('0', '1')
return (p, "")
end
return (p[1:diff - 1], p[diff + 1:mid])
end
"Unpair recursively till bottom of tree"
function ⤈(p::String)
p′, word = ↓(p)
if p′ == p return p′ end
return (⤈(p′), word)
end
encoded = ("Hello" ↑ "world") ↑ "!"
⤈(encoded) # (("Hello", "world"), "!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment