We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
+ 0 comments def factorial(n) total = n for i in 1...n do total *= i end yield total end n = gets.to_i factorial(n) do |num| puts num end
+ 0 comments def factorial(n) yield(n) end n = gets.to_i puts factorial(n) { (1..n).reduce(1, :*) }
+ 0 comments def factorial(n, i) yield(n, i) end n = gets.to_i i = n - 1 puts factorial(n, i) { while i != 0 n = n * i i -= 1 end n }
+ 0 comments Here is blocks problem solution - https://www.gyangav.com/2022/10/hackerrank-ruby-blocks-problem-solution.html
+ 0 comments def factorial yield end n = gets.to_i factorial do puts (1..n).reduce(:*) end
Load more conversations
Sort 96 Discussions, By:
Please Login in order to post a comment