Advertisement
zvoulgaris

RLE drill

Feb 9th, 2021
2,776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.63 KB | None | 0 0
  1. # RLE basic
  2.  
  3. function main(x::String)
  4.     n = length(x) # number of characters in input
  5.     y = Array{Tuple}(undef, n) # output array
  6.     tc = 0 # touple counter semaphore
  7.     c = 1 # another counter semaphore
  8.     last_character = x[1] # the character to register in the output array
  9.  
  10.     for i = 2:n
  11.         new_character = x[i]
  12.  
  13.         if new_character == last_character
  14.             c += 1
  15.         else
  16.             tc += 1
  17.             y[tc] = (last_character, c)
  18.             c = 1
  19.             last_character = new_character
  20.         end
  21.     end
  22.  
  23.     tc += 1
  24.     y[tc] = (last_character, c)
  25.     return y[1:tc]
  26. end
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement