Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Question

added 12 characters in body
Source Link

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a\$a\$ and b\$b\$, tell if ab-1\$a^b-1\$ is a prime number.
  2. Given integers a\$a\$ and b\$b\$, return nCr\$a\choose b\$ (a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want. For task 1, you can return a truthy/falsy value or choose two values to mean true and false and return them accordingly. Eg. you can choose that "prime" means true and "not prime" means false.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type. You can assume that the input is valid.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1\$a^b-1\$ is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr\$a\choose b\$

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr (a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want. For task 1, you can return a truthy/falsy value or choose two values to mean true and false and return them accordingly. Eg. you can choose that "prime" means true and "not prime" means false.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type. You can assume that the input is valid.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792

In this challenge we try to solve two important problems at once. They are:

  1. Given integers \$a\$ and \$b\$, tell if \$a^b-1\$ is a prime number.
  2. Given integers \$a\$ and \$b\$, return \$a\choose b\$.

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want. For task 1, you can return a truthy/falsy value or choose two values to mean true and false and return them accordingly. Eg. you can choose that "prime" means true and "not prime" means false.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type. You can assume that the input is valid.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

\$a^b-1\$ is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

\$a\choose b\$

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792
Tweeted twitter.com/StackCodeGolf/status/849660432575070209
clarified
Source Link
fergusq
  • 5.2k
  • 1
  • 19
  • 37

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want. For task 1, you can return a truthy/falsy value or choose two values to mean true and false and return them accordingly. Eg. you can choose that "prime" means true and "not prime" means false.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type. You can assume that the input is valid.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want. For task 1, you can return a truthy/falsy value or choose two values to mean true and false and return them accordingly. Eg. you can choose that "prime" means true and "not prime" means false.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type. You can assume that the input is valid.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792
Post Reopened by Toto, Community Bot, Titus, Rohan Jhunjhunwala, Thunda
clarified and added test cases
Source Link
fergusq
  • 5.2k
  • 1
  • 19
  • 37

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want.

  2. The programsalgorithms you use must not contain unusedwork for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want.

  2. The programs must not contain unused code, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  3. Standard loopholes are not allowed.

In this challenge we try to solve two important problems at once. They are:

  1. Given integers a and b, tell if ab-1 is a prime number.
  2. Given integers a and b, return nCr(a, b).

Specifically, you must write two programs, one that does the first task and one that does the other. As we want to solve both problems at once, it is encouraged to use a same piece of code in both programs.

Scoring

The score of an answer is the Levenshtein distance between the two programs. Lower score is better. In case of a tie, the answer with the shortest combined code of the two programs wins. You can use this script to calculate the score of your solution.

Rules

  1. You must write two programs in the same language that solve the tasks described above. You can use any I/O methods you want.

  2. The algorithms you use must work for all possible inputs, but it is OK if the code fails for large numbers due to limitations of the used number type.

  3. No subset of the program must solve the problem, ie. the code must not work if any character(s) are removed. For example, the following code is not valid, because it is possible to remove the unused else-block without breaking the program:

     if (1) { /* change to 0 to get the second program*/
     ...
     } else {
     ...
     }
    
  4. Standard loopholes are not allowed.

Test cases

ab-1 is prime?

a b
1 1 false
2 3 true
5 2 false
2 5 true
4 3 false
2 7 true

nCr

a b nCr(a,b)
1 1 1
5 2 10
4 3 4
10 7 120
12 5 792
Post Closed as "Needs details or clarity" by xnor, Martin Ender
Added a link to Martin Ender's Levenshtein distance script from the comments.
Source Link
Steadybox
  • 16.6k
  • 5
  • 42
  • 84
Loading
clarified rules + link to nCr
Source Link
fergusq
  • 5.2k
  • 1
  • 19
  • 37
Loading
edited tags
Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 998
Loading
edited tags
Link
user41805
  • 13.4k
  • 6
  • 43
  • 88
Loading
added an example
Source Link
fergusq
  • 5.2k
  • 1
  • 19
  • 37
Loading
Source Link
fergusq
  • 5.2k
  • 1
  • 19
  • 37
Loading

AltStyle によって変換されたページ (->オリジナル) /