Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerRank Partial Applications problem solution in ruby

YASH PAL, 31 July 202429 January 2026

In this HackerRank Partial Applications problem solution in ruby programming In Partial Application, we create a lambda that takes a parameter and returns a lambda that does something with it.

Example:

multiply_function = -> (number) do

   -> (another_number) do

       number * another_number

   end

end

doubler = multiply_function.(2)

tripler = multiply_function.(3)

puts doubler.(4)

puts tripler.(4)

In the above example, the lambda will take number as a parameter, and return a lambda. When you call this lambda with another_number, it will return the product of the two.

Task

You are given a partially complete code. Your task is to fill in the blanks (_______).

Here, the combination is a variable that stores a partial application that computes combination nCr.

HackerRank Partial Applications problem solution in ruby

Partial Applications problem solution in ruby.

class Integer
  def fact
    (1..self).reduce(:*) || 1
  end
end
combination = -> (n) do
    -> (r) do
        n.fact / (r.fact*(n-r).fact)
    end
end
n = gets.to_i
r = gets.to_i
nCr = combination.(n)
puts nCr.(r)

Partial Applications problem solution in ruby.

combination = -> (n) do
   -> (r) do
       top = (n-r+1..n).reduce(:*)
       top/(1..r).reduce(:*)
   end
end

n = gets.to_i
r = gets.to_i
nCr = combination.(n)
puts nCr.(r)

coding problems solutions Hackerrank Problems Solutions Ruby Solutions HackerRankruby

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes