Thursday 12 May 2022

Partial Permutations (Rosalind | English)

rosalind


Hi everyone, how are you? This time, I want to discuss about one problem (bioinformatics problem) that exists in rosalind.info's web. The title is "Partial Permutations". For the reference, you can first check out the problem that will be discussed (here). 

Overview 

In this problem we will given 2 integers representing "the amount of the taken numbers" and "the total amount of the existing numbers". Let's call them k and n. Our task is to determine the permutation of P(n, k) (this problem is based on the permutation problem that we have learned in high school). 

The Code 

This is the code for solving this problem (with java language): 
  1. static void solve() {
  2. int n = ni();
  3. int k = ni();
  4. long res = 1L;
  5. for (int i = n; i > n - k; i--) {
  6. res *= i;
  7. res %= 1000000;
  8. }
  9. out.println(res);
  10. }
  11.     
The Code Description

It seems clear enough, the answer is (n - k)!. So, we can immediately print the answer by modulo 1.000.000 (line 5-8).

Input and Output

In the code above, I used ni() function for entering the integer-form data (line 2-3). That function is an extension of one of the system inputs which are available in java, it's called BufferedReader. 

And for the output I used out.println() function (line 9). That function is a modification from System.out.println() function which is very familiar in java. You can see the additional code for that modification (input and output) in my complete code at github

That's it. If you want to ask something, you can write it in the comment section below. I hope this article is useful and see you in the next article! 


Reference :
Source of image 1 :https://www.facebook.com/ProjectRosalind/

No comments:

Post a Comment