Skip to content

Instantly share code, notes, and snippets.

@mkf-simpson
Created July 15, 2015 09:03
Show Gist options
  • Save mkf-simpson/f58e7f3c09ff8142a892 to your computer and use it in GitHub Desktop.
Save mkf-simpson/f58e7f3c09ff8142a892 to your computer and use it in GitHub Desktop.
# Генерирует следующую строку последовательности
def sequence(str)
i = 0
count = 1
start = 0
str2=''
while i < str.length
if str[i+1] == str[start]
i = i + 1
count = count + 1
else
str2 = str2 + count.to_s + str[start].to_s
count = 1
i = i + 1
start = i
end
end
return str2
end
#Записывает первый n элементов последовательности
def all_sequence(n)
z='1'
for i in 1..n
puts z
z=sequence(z)
end
end
all_sequence(10)
c = [4,5,6,7,8,9]
#возводит в квадрат и инвертирует строку
def seq2(mass)
mass.each do |number|
puts number.to_s + ' ' + (number**2).to_s.reverse
end
end
seq2(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment