Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
alex
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilsC8 committed Jun 9, 2024
1 parent ef37239 commit 3158b5e
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private static BigInteger factorial(int n) {
}
return result;
}

public static Result<BigInteger, Exception> Comb_sin_repeticion(String[] args) {
var this_function = new Object() {}.getClass().getEnclosingMethod().getName();
try {
Expand Down Expand Up @@ -51,17 +52,41 @@ public static Result<BigInteger, Exception> Varianza_sin_repeticion(String[] arg

public static Result<BigInteger, Exception> Varianza_con_repeticion(String[] args) {
var this_function = new Object() {}.getClass().getEnclosingMethod().getName();
return Result.error(new UnsupportedOperationException(this_function + " Not supported yet."));
try {
int n = Integer.parseInt(args[0]);
int r = Integer.parseInt(args[1]);
BigInteger result = BigInteger.valueOf(n).pow(r);
return Result.ok(result);
} catch (Exception e) {
return Result.error(e);
}
}

public static Result<BigInteger, Exception> Permutacion_sin_repeticion(String[] args) {
var this_function = new Object() {}.getClass().getEnclosingMethod().getName();
return Result.error(new UnsupportedOperationException(this_function + " Not supported yet."));
try {
int n = Integer.parseInt(args[0]);
return Result.ok(factorial(n));
} catch (Exception e) {
return Result.error(e);
}
}

public static Result<BigInteger, Exception> Permutacion_con_repeticion(String[] args) {
var this_function = new Object() {}.getClass().getEnclosingMethod().getName();
return Result.error(new UnsupportedOperationException(this_function + " Not supported yet."));
try {
int n = Integer.parseInt(args[0]);
int[] counts = new int[args.length - 1];
for (int i = 1; i < args.length; i++) {
counts[i - 1] = Integer.parseInt(args[i]);
}
BigInteger denominator = BigInteger.ONE;
for (int count : counts) {
denominator = denominator.multiply(factorial(count));
}
return Result.ok(factorial(n).divide(denominator));
} catch (Exception e) {
return Result.error(e);
}
}

}

0 comments on commit 3158b5e

Please sign in to comment.