In this challenge we try to solve two important problems at once. They are:
- Given integers \$a\$ and \$b\$, tell if \$a^b-1\$ is a prime number.
- 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
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.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.
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 { ... }
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