zvoulgaris

RLE drill

Feb 9th, 2021
553
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×