Created
June 9, 2011 08:46
-
-
Save timurvafin/1016355 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ar = [1] | |
iter = 1 | |
iterCount = 10 | |
result = [] | |
while (iter < iterCount) | |
result = [] | |
i = 0 | |
j = 0 | |
e = ar.length - 1 | |
flag = true | |
flag2 = true | |
while (flag2) | |
flag = true | |
i = j | |
var_prev = ar[i] | |
counter = 1 | |
if i == e | |
flag = false | |
flag2 = false | |
result.push counter | |
result.push var_prev | |
end | |
while (flag) | |
i = i + 1 | |
var_next = ar[i] | |
if var_next != var_prev | |
flag = false | |
result.push counter | |
result.push var_prev | |
j = i | |
counter = 1 | |
else | |
counter = counter + 1 | |
end | |
var_prev = var_next | |
if i == e | |
flag = false | |
flag2 = false | |
result.push counter | |
result.push var_prev | |
end | |
end | |
end | |
str = '' | |
result.each do |item| | |
str = str + item.to_s | |
end | |
puts str | |
puts | |
ar = result | |
iter = iter + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment