Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjunto ejercicios de Eduardo y Gina #28

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
56ad29b
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 19, 2022
f1970b7
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 19, 2022
ed2f905
Agrego la resolucion del ejercicio y los test hechos
GavottiGuillermo Jul 19, 2022
f143294
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 19, 2022
3ac042d
Agrego ejercicios de Eduardo y Gina con los respectivos test
GavottiGuillermo Jul 19, 2022
47251e5
Merge branch '1907'
GavottiGuillermo Jul 19, 2022
a6c33e9
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 20, 2022
01d2c78
Merge branch 'main' of https://github.com/fahelodev/bc9 into 2007
GavottiGuillermo Jul 20, 2022
a3683be
Agrego KataReverse, KataReverseTest y .gitatributes
GavottiGuillermo Jul 20, 2022
950b32b
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 20, 2022
ef0da40
Renombro archivos.
GavottiGuillermo Jul 20, 2022
47cad9a
Renombro archivos.
GavottiGuillermo Jul 20, 2022
7d5a1f1
Borro archivos que dan errores
GavottiGuillermo Jul 20, 2022
27d1822
Actualizo gradle
GavottiGuillermo Jul 20, 2022
377eae1
Agrego TenMinWalk y elimino un archivo que me da error
GavottiGuillermo Jul 20, 2022
f3f4a60
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 21, 2022
d4b7b60
Agrego ejercicios Java en equipo
GavottiGuillermo Jul 25, 2022
55f143f
Merge branch 'EjercicioFighter'
GavottiGuillermo Jul 25, 2022
bd19fa1
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 25, 2022
81ca243
Merge branch 'main' of https://github.com/fahelodev/bc9
GavottiGuillermo Jul 25, 2022
8a7c575
Merge branch 'main' of https://github.com/GavottiGuillermo/bc9
GavottiGuillermo Jul 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/main/java/dleiva/Calculator.java

This file was deleted.

100 changes: 100 additions & 0 deletions src/main/java/gGavotti/BuyCar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package gGavotti;

/*
A man has a rather old car being worth $2000. He saw a secondhand car being worth $8000.
He wants to keep his old car until he can buy the secondhand one.

He thinks he can save $1000 each month but the prices of his old car and of the new one decrease of 1.5 percent per month.
Furthermore this percent of loss increases of 0.5 percent at the end of every two months.
Our man finds it difficult to make all these calculations.

Can you help him?

How many months will it take him to save up enough money to buy the car he wants,
and how much money will he have left over?

Parameters and return of function:

parameter (positive int or float, guaranteed) start_price_old (Old car price)
parameter (positive int or float, guaranteed) start_price_new (New car price)
parameter (positive int or float, guaranteed) saving_per_month
parameter (positive float or int, guaranteed) percent_loss_by_month

nbMonths(2000, 8000, 1000, 1.5) should return [6, 766] or (6, 766)
Detail of the above example:
end month 1: percent_loss 1.5 available -4910.0
end month 2: percent_loss 2.0 available -3791.7999...
end month 3: percent_loss 2.0 available -2675.964
end month 4: percent_loss 2.5 available -1534.06489...
end month 5: percent_loss 2.5 available -395.71327...
end month 6: percent_loss 3.0 available 766.158120825...
return [6, 766] or (6, 766)
where 6 is the number of months at the end of which he can buy the new car and 766 is the nearest integer to 766.158... (rounding 766.158 gives 766).

Note:

Selling, buying and saving are normally done at end of month.
Calculations are processed at the end of each considered month but if,
by chance from the start, the value of the old car is bigger than the value of the new one or equal there is no saving to be made,
no need to wait so he can at the beginning of the month buy the new car:

nbMonths(12000, 8000, 1000, 1.5) should return [0, 4000]
nbMonths(8000, 8000, 1000, 1.5) should
*/
public class BuyCar {

public static void main(String[] args) {

int[]arr =BuyCar.nMeses(2000,8000,1000,1.5);
System.out.println("*****************************************************************");
System.out.println("*****************************************************************");
System.out.println("*****************************************************************");
System.out.println("Mes de la compra del vehiculo: "+arr[0]+"\nVarlor sobrante $"+arr[1]+" dorales");
System.out.println("*****************************************************************");
System.out.println("*****************************************************************");
System.out.println("*****************************************************************");
/*System.out.println("Mes de la compra del vehiculo: "+arr2[0]+"\nVarlor sobrante "+arr2[1]);
System.out.println("Mes de la compra del vehiculo: "+arr3[0]+"\nVarlor sobrante "+arr3[1]);
int[]arr2 =BuyCar.nMeses(12000,8000,1000,1.5);
int[]arr3 =BuyCar.nMeses(8000,8000,1000,1.5);
*/
}

static int[] nMeses(int priceOld,int priceNew,int savingsPerMonth,double lossByMonth){

int dineroGuardado=0;
int meses =0;
while(getDiferenciaPrecioVehiculos(priceOld, priceNew) >dineroGuardado) { //comparamos los precios ( restando los valores del nuevo con el viejo por cada mes Con el valor dineroGuardado
if(++meses % 2 ==0) { // comprueba si el numero es par
lossByMonth += .5; //aumento a variable perdida por mes
}

priceOld -= getDescuentoMensualAutoViejo(priceOld, lossByMonth); // el resultado del metodo restara el precio actual del auto redondeando su valor
priceNew -= getDescuentoMensualAutoNuevo(priceNew, lossByMonth); //
dineroGuardado += savingsPerMonth; // aumentara por cada itaracion
}


int dineroSobrante= getDineroSobrante(priceOld, priceNew, dineroGuardado); // actualizamos el valor que sobra
return new int[]{meses, dineroSobrante};// se retorna en un arr
}

private static int getDineroSobrante(int priceOld, int priceNew, int dineroGuardado) {
return priceOld - priceNew + dineroGuardado;
}

private static long getDescuentoMensualAutoNuevo(int priceNew, double lossByMonth) { //// realiza el redondeo
return Math.round(priceNew * lossByMonth / 100);
}

private static long getDescuentoMensualAutoViejo(int priceOld, double lossByMonth) { // se aplica redondeo multiplicamos
return Math.round(priceOld * lossByMonth / 100);
}

private static int getDiferenciaPrecioVehiculos(int priceOld, int priceNew) {
return priceNew - priceOld;
}



}
67 changes: 67 additions & 0 deletions src/main/java/gGavotti/CountingDuplicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package gGavotti;

/**
* Contar el número de duplicados
*
* Escriba la función duplicateCount, que devuelva
* el numero (entero) de letras duplicadas.
*
* String de entrada:
* 1. distinct case-insensitive
* 2. Acepta solo Alfanumericos
*
* Ejemplos de retornos de la funcion
*
* "abcde" -> 0 # ningún carácter se repite más de una vez
* "aabbcde" -> 2 # 'a' y 'b'
* "aabBcde" -> 2 # 'a' aparece dos veces y 'b' dos veces (`b` y` B`)
* "indivisibility" -> 1 # 'i' aparece seis veces
* "aA11" -> 2 # 'a' y '1'
* "ABBA" -> 2 # 'A' y 'B' ocurren dos veces
*/


public class CountingDuplicates {
public static int duplicateCount(String text) {

//Pogo todas las letras en minuscula.
//Hago un array que guarde las letras ya suamdas.
//Recorro text hasta lenght - 1 para no salir de rango.

text.toLowerCase();
char [] LetrasContadas = new char[text.length()];
int contador=0;

for(int i=0; i<text.length()-1;i++){

for(int j=i+1; j<text.length();j++){

//Creo la funcion "fueContada" que devuelve si la letra ya se encuentra en el array de LetrasContadas.
if(text.charAt(i)==text.charAt(j) && !fueContada(text.charAt(i), LetrasContadas)){

contador++;
LetrasContadas[i]=text.charAt(i);

}
}
}
return contador;
}

private static boolean fueContada(char c, char[] LetContadas) {

boolean seEncuentra=false;
for(int i=0; i<LetContadas.length;i++){

if (c == LetContadas[i]) {
seEncuentra=true;
break;
}
}
return seEncuentra;
}

public static void main(String []args){
System.out.println(duplicateCount("aabbccccczzz"));
}
}
52 changes: 52 additions & 0 deletions src/main/java/gGavotti/DigPow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package gGavotti;

/*
Some numbers have funny properties. For example:

89 --> 8&sup1; + 9&sup2; = 89 * 1

695 --> 6&sup2; + 9&sup3; + 5&#x2074;= 1390 = 695 * 2

46288 --> 4&sup3; + 6&#x2074;+ 2&#x2075; + 8&#x2076; + 8&#x2077; = 2360688 = 46288 * 51

Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p

we want to find a positive integer k, if it exists, such that the sum of the digits of n taken to the successive powers of p is equal to k * n.
In other words:

Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k

If it is the case we will return k, if not return -1.

Note: n and p will always be given as strictly positive integers.

digPow(89, 1) should return 1 since 8&sup1; + 9&sup2; = 89 = 89 * 1
digPow(92, 1) should return -1 since there is no k such as 9&sup1; + 2&sup2; equals 92 * k
digPow(695, 2) should return 2 since 6&sup2; + 9&sup3; + 5&#x2074;= 1390 = 695 * 2
digPow(46288, 3) should return 51 since 4&sup3; + 6&#x2074;+ 2&#x2075; + 8&#x2076; + 8&#x2077;
*/


public class DigPow {
public static long digPow(int n, int p) {

String nString = String.valueOf(n);
long sumatoria = 0;

for (int i = 0; i < nString.length(); i++)
sumatoria += (long) Math.pow(ObtenerUnEntero(nString, i), p + i);

if (sumatoria % n == 0) return sumatoria / n;
else return -1;

}

private static int ObtenerUnEntero(String nString, int i) {
return Integer.parseInt(String.valueOf(nString.charAt(i)));
}
}





2 changes: 2 additions & 0 deletions src/main/java/gGavotti/Estructuras.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package gGavotti;public class Estructuras {
}
16 changes: 16 additions & 0 deletions src/main/java/gGavotti/Fighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gGavotti;


public class Fighter {
public String name;
public int health, damagePerAttack;

public Fighter(String name, int health, int damagePerAttack) {
this.name = name;
this.health = health;
this.damagePerAttack = damagePerAttack;
}

}


78 changes: 78 additions & 0 deletions src/main/java/gGavotti/KataFighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package gGavotti;

import java.util.*;


public class KataFighter {

public static void main(String[] args) {

Fighter Luchador1 = new Fighter("Guille", 7, 3);
Fighter Luchador2 = new Fighter("Alexis", 8, 2);

System.out.println("El ganador es " + declareWinner(Luchador1, Luchador2, "Carlos"));


}


public static String declareWinner(Fighter fighter1, Fighter fighter2, String firstAttacker) {

if (firstAttacker == fighter1.name) {
while (fighter1.health > 0 && fighter2.health > 0) {

fighter2.health -= fighter1.damagePerAttack;

if (fighter2.health > 0) {
System.out.println(fighter1.name + " ataca a " + fighter2.name + " .Ahora " + fighter2.name + " tiene " + fighter2.health + " de vida.");
} else {
System.out.println(fighter1.name + " ataca a " + fighter2.name);
System.out.println(fighter2.name + " murió! ");
}
if (fighter2.health <= 0) return fighter1.name;

fighter1.health -= fighter2.damagePerAttack;

if (fighter1.health > 0) {
System.out.println(fighter2.name + " ataca a " + fighter1.name + " .Ahora " + fighter1.name + " tiene " + fighter1.health + " de vida.");
} else {
System.out.println(fighter2.name + " ataca a " + fighter1.name);
System.out.println(fighter1.name + " murió! ");
}

if (fighter1.health <= 0) return fighter2.name;
}

} else {
while (fighter1.health > 0 && fighter2.health > 0) {

fighter1.health -= fighter2.damagePerAttack;

if (fighter1.health > 0) {
System.out.println(fighter2.name + " ataca a " + fighter1.name + " .Ahora " + fighter1.name + " tiene " + fighter1.health + " de vida.");
} else {
System.out.println(fighter2.name + " ataca a " + fighter1.name);
System.out.println(fighter1.name + " murió! ");
}

if (fighter1.health <= 0) return fighter2.name;

fighter2.health -= fighter1.damagePerAttack;

if (fighter2.health > 0) {
System.out.println(fighter1.name + " ataca a " + fighter2.name + " .Ahora " + fighter2.name + " tiene " + fighter2.health + " de vida.");
} else {
System.out.println(fighter1.name + " ataca a " + fighter2.name);
System.out.println(fighter2.name + " murió! ");
}

if (fighter2.health <= 0) return fighter1.name;

}

}


return "";
}
}
50 changes: 50 additions & 0 deletions src/main/java/gGavotti/KataReverseWords.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gGavotti;

import java.lang.*;

/*
Complete the function that accepts a string parameter, and reverses each word in the string.
All spaces in the string should be retained.
*/

public class KataReverseWords {

public static void main(String[] args) {

System.out.println(reverseWords(" Hola muNdoO"));

}

public static String reverseWords(final String original) {

//Creo variable primera letra que apunte a la primera letra de cada palabra
String respuesta = "";
int j = 0;
int primera_letra = 0;

while (j < original.length()-1) {

//Chequeo los espacios en blanco
while (original.charAt(j) == ' ' && j < original.length()) {
respuesta += original.charAt(j);
j++;
}
primera_letra = j;

// Avanzo sobre la palabra hasta dejar la j en el primer espacio en blanco.
while (original.charAt(j) != ' ' && j < original.length()-1) j++;

int i;
if (j != original.length()-1) i=j;else i=j+1; //Compruebo para no salir de rango.

//Recorro la palabra hacia atras y voy guardando en la respuesta.
while (i > primera_letra) {
respuesta += original.charAt(i-1);// Asigno i-1 ya que j esta en el primer espacion en blanco.
i--;
}

}
return respuesta;
}

}
Loading