Created
July 15, 2015 09:03
-
-
Save mkf-simpson/f58e7f3c09ff8142a892 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
# Генерирует следующую строку последовательности | |
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) |
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
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