Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RLE basic
- function main(x::String)
- n = length(x) # number of characters in input
- y = Array{Tuple}(undef, n) # output array
- tc = 0 # touple counter semaphore
- c = 1 # another counter semaphore
- last_character = x[1] # the character to register in the output array
- for i = 2:n
- new_character = x[i]
- if new_character == last_character
- c += 1
- else
- tc += 1
- y[tc] = (last_character, c)
- c = 1
- last_character = new_character
- end
- end
- tc += 1
- y[tc] = (last_character, c)
- return y[1:tc]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement