Created
April 25, 2013 17:10
-
-
Save airvzxf/5461405 to your computer and use it in GitHub Desktop.
Codecery :: Exercise 002
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
##### Adds | |
puts "Adds n + (n-x)." | |
#print "Input an integer number: " | |
#n = gets | |
n = 5 | |
(n).downto(0) do |a| | |
x = n-a | |
break if a < x | |
puts "#{a} + #{x} = #{a+x}" | |
end | |
puts '' | |
##### Get Cube for n. | |
def getOdd(n) | |
x = [] | |
(n).times { |a| x << a if a%2 != 0 } | |
x | |
end | |
def getStart(n) | |
x = 0 | |
(0..n-1).each { |z| x += z } | |
x * 2 + 1 | |
end | |
puts "Get Cube for n." | |
#print "Input an integer number: " | |
#n = gets | |
n = 4 | |
n_i = getOdd(200) | |
(1..10).each do |x| | |
n = x | |
puts "Number: #{n}" | |
m = getStart(n) | |
s = 0 | |
n2 = n | |
puts "#{n} * 3 = #{m}" | |
n_i.each do |a| | |
if a >= m then | |
n2 -= 1 | |
s = s + a | |
print a | |
if n2 == 0 then | |
break | |
else | |
print " + " | |
end | |
end | |
end | |
print " = #{s}\n\r" | |
puts "Test: #{n**3} ?== #{s}" | |
puts '' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment