From 3158b5eddb0eb8a20fe40271c8993d7a1e96dc6a Mon Sep 17 00:00:00 2001 From: Philasarts <165176234+PhilsC8@users.noreply.github.com> Date: Sun, 9 Jun 2024 01:23:13 +0000 Subject: [PATCH] alex --- .../clsEstructuraDiscretas/pry4/Formulas.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java b/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java index 9e2d71a..c770ee1 100644 --- a/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java +++ b/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java @@ -16,6 +16,7 @@ private static BigInteger factorial(int n) { } return result; } + public static Result Comb_sin_repeticion(String[] args) { var this_function = new Object() {}.getClass().getEnclosingMethod().getName(); try { @@ -51,17 +52,41 @@ public static Result Varianza_sin_repeticion(String[] arg public static Result 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 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 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); + } } - }