Created
December 8, 2011 12:39
-
-
Save ka8725/1446879 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
def armstrong_number(num) | |
s_num = num.to_s | |
len = s_num.length | |
sc = s_num.split(//).inject(0) {|sum, i| sum + i.to_i * len} # inject как ты уже понял проходится по всему | |
# массиву и еще плюс к тому же сохраняет сумму. | |
# Сумму ты составляешь сам. 0 здесь первоначальное состояние суммы | |
puts (num == sc ? "BINGO! #{s_num} - является числом Армстронга" : "#{s_num} - не является числом Армстронга") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment