Created
December 14, 2010 20:35
-
-
Save Talleyran/741054 to your computer and use it in GitHub Desktop.
This file contains 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
#encoding: utf-8 | |
#Программа написана для ruby 1.9.2 | |
def get_next seq | |
puts next_seq = seq.split('').inject( [] ){ |s,w| | |
if s[-1].nil? || s[-1][1] != w | |
s << [1,w] | |
else | |
s[-1][0]+=1 | |
end | |
s | |
}.join | |
puts 'Хотите узнать следующее число последовательности?' | |
get_next next_seq if ['y','yes'].include? gets.strip.force_encoding( 'utf-8' ) #т.к. не факт, что у пользователя в консоли utf | |
end | |
puts 'Введите первый член последовательности' | |
v = gets.strip | |
if v =~ /[0-9]+/ | |
get_next v | |
else | |
puts 'Некорректный ввод' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment