From d460995efca684d5e120b2718793330b7376c67f Mon Sep 17 00:00:00 2001 From: Philasarts <165176234+PhilsC8@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:10:03 +0000 Subject: [PATCH] third commit --- .../clsEstructuraDiscretas/pry4/Formulas.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java b/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java index 090c795..9e2d71a 100644 --- a/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java +++ b/src/main/java/com/utp/clsEstructuraDiscretas/pry4/Formulas.java @@ -6,19 +6,47 @@ public class Formulas { + private static BigInteger factorial(int n) { + if (n == 0) { + return BigInteger.ONE; + } + BigInteger result = BigInteger.ONE; + for (int i = 1; i <= n; i++) { + result = result.multiply(BigInteger.valueOf(i)); + } + return result; + } public static Result Comb_sin_repeticion(String[] args) { var this_function = new Object() {}.getClass().getEnclosingMethod().getName(); - return Result.error(new UnsupportedOperationException(this_function + " aun no esta listo.")); + try { + int n = Integer.parseInt(args[0]); + int r = Integer.parseInt(args[1]); + return Result.ok(factorial(n).divide(factorial(r).multiply(factorial(n - r)))); + } catch (Exception e) { + return Result.error(e); + } } public static Result Comb_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]); + return Result.ok(factorial(n + r - 1).divide(factorial(r).multiply(factorial(n - 1)))); + } catch (Exception e) { + return Result.error(e); + } } public static Result Varianza_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]); + int r = Integer.parseInt(args[1]); + return Result.ok(factorial(n).divide(factorial(n - r))); + } catch (Exception e) { + return Result.error(e); + } } public static Result Varianza_con_repeticion(String[] args) {