Created
April 26, 2013 16:40
-
-
Save airvzxf/5468631 to your computer and use it in GitHub Desktop.
Codecery :: Exercise 003
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
##### Perfect Number | |
puts "This is the perfect number." | |
x = 30 | |
(x).times do |n| | |
(n).downto(1) do |a| | |
#puts "a: #{a}" | |
d = 0 | |
(1..a).each do |b| | |
if a % b == 0 | |
#puts "b: #{b}" | |
d += b if b != a | |
end | |
end | |
#puts "d: #{d}" | |
#puts '' | |
if d == a | |
puts "Start at number: #{n}" | |
puts "The perfect number is: #{d}\n\r" | |
break | |
end | |
end | |
end | |
##### Where Decimal | |
puts "Where are the Decimal number." | |
print "Input the number sequence: " | |
m = gets.to_i | |
#m = 1234567891011121314 | |
print "Input the number N: " | |
n = gets.to_i | |
#n = 111 | |
puts "The position is: #{m.to_s.index(n.to_s)+1}" | |
puts '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment