result = n * (n - 1) * (n - 2) * ... * 2 * 1
I write a Ruby program.
n = gets.to_iThis is a normal program.
k = 1
n.times do |i|
k *= i.next
end
puts k
Let's write in one line.
k = 1It's easy so far.
gets.to_i.times { |i| k *= i.next }
puts k
A little device.
k = 1
puts k if gets.to_i.times { |i| k *= i.next }
The key point is the initialization of a variable.
lambda { |k| puts k if gets.to_i.times { |i| k *= i.next } }.call(1)Completion!
No comments:
Post a Comment