Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-e003-generala
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Rolon
java-e003-generala
Commits
7b0aff96
You need to sign in or sign up before continuing.
Commit
7b0aff96
authored
Oct 19, 2018
by
Pedro Rolon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se agregaron los archivos correspondientes a la tarea!
parents
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
0 deletions
+171
-0
Generala.java
+146
-0
README.md
+6
-0
respuestas.txt
+19
-0
No files found.
Generala.java
0 → 100644
View file @
7b0aff96
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
import
java.io.File
;
public
class
Generala
{
//
//
//
// class Generala
// ESTA ES LA FUNCIÓN QUE HAY QUE IMPLEMENTAR
// TAMBIÉN PUEDEN AGREGAR OTRAS FUNCIONES y/o CLASES
// QUE NECESITEN PARA RESOLVER EL EJERCICIO DE LA
// MANERA MÁS ORDENADA POSIBLE
String
jugada
(
String
dados
)
{
//System.out.println(dados.charAt(0));
//comprobar que sean 5 valores
if
(
dados
.
length
()
!=
5
){
return
"INVALIDO"
;
}
//Para comprobar los tres casos posibles de escalera
if
(
dados
.
equals
(
"12345"
)
||
dados
.
equals
(
"23456"
)
||
dados
.
equals
(
"34561"
)){
return
"ESCALERA"
;
}
//array para tener la cantidad de apariciones de un número
int
[]
cantidad
=
{
0
,
0
,
0
,
0
,
0
,
0
};
for
(
int
i
=
0
;
i
<
dados
.
length
();
i
++){
// para castear char a int
int
index
=
dados
.
charAt
(
i
)
-
48
;
//comprueba que los valores sean válidos, del 1 al 6
if
(
index
<
1
||
index
>
6
){
return
"INVALIDO"
;
}
cantidad
[
index
-
1
]++;
}
//calcula el máximo del vector cantidad
int
max
=
maximo
(
cantidad
);
//System.out.println(max);
if
(
max
==
5
){
return
"GENERALA"
;
}
if
(
max
==
4
){
return
"POKER"
;
}
if
(
max
==
3
){
cantidad
[
indiceDe
(
cantidad
,
max
)]
=
0
;
max
=
maximo
(
cantidad
);
if
(
max
==
2
){
return
"FULL"
;
}
}
return
"NADA"
;
}
//encuentra el valo máximo de un array
int
maximo
(
int
[]
input
){
int
max
=-
1
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++){
if
(
input
[
i
]>
max
){
max
=
input
[
i
];
}
}
return
max
;
}
//encuentra el índice de un elemento
int
indiceDe
(
int
[]
input
,
int
elemento
){
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
if
(
input
[
i
]==
elemento
){
return
i
;
}
}
//retorna -1 si no lo encuentra
return
-
1
;
}
/*
// Ustedes pueden ignorar esto
String[] jugadas(String[] losdados)
{
String[] ret = new String[losdados.length];
int i = 0;
for (String dados : losdados)
{
ret[i] = this.jugada(dados);
i++;
}
return ret;
}
// Ustedes pueden ignorar esto
static String[] processBatch(String fileName) throws Exception
{
Scanner sc = new Scanner(new File(fileName));
List<String> lines = new ArrayList<String>();
while (sc.hasNextLine()) {
lines.add(sc.nextLine());
}
return lines.toArray(new String[0]);
}
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Generala
g
=
new
Generala
();
/* IGNORAR PORQUE ESTO NO SE VA A EJECUTAR PARA USTEDES */
/*
if (args.length > 0) {
String[] jugadas = processBatch(args[0]);
String resultados[] = g.jugadas(jugadas);
for(String res : resultados) {
System.out.println(res);
}
return;
}
*/
// ESTO SI SE EJECUTA PARA USTEDES
/*
System.out.println(g.jugada("12345")); //ESCALERA
System.out.println(g.jugada("23456")); //ESCALERA
System.out.println(g.jugada("34561")); //ESCALERA
System.out.println(g.jugada("22222")); //GENERALA
System.out.println(g.jugada("23223")); //FULL
System.out.println(g.jugada("43434")); //FULL
System.out.println(g.jugada("43435")); //NADA
System.out.println(g.jugada("2322")); //INVALIDO
System.out.println(g.jugada("232823"));//INVALIDO
System.out.println(g.jugada("23A23")); //INVALIDO
System.out.println(g.jugada("55155")); //POKER
*/
}
}
\ No newline at end of file
README.md
0 → 100644
View file @
7b0aff96
# COMENTARIOS
*
El archivo con el código es
**Generala.java**
*
Comenté todas las lineas que el ejercicio decia
**ignorar**
, descomentar para realizar la prueba.
*
Agregué lineas para testear, pero las comenté para que no afecten al resultado.
*
Las preguntas las respondo en otro archivo llamado
**respuestas.txt**
, número
**2**
y la número
**3**
\ No newline at end of file
respuestas.txt
0 → 100644
View file @
7b0aff96
2. Responder a las siguientes preguntas
2.1. Cuál es la probabilidad de sacar generala en un tiro
es de 0.077%
2.2. Cuál es la probabilidad de sacar poker en un tiro
es de 1.92%
2.3. Cuál es la probabilidad de sacar full en un tiro
es de 3.85%
2.4. Cuál es la probabilidad de sacar escalera en un tiro
es de 4.61%
3. BONUS
3.1. Cuál es la probabilidad de sacar generala en dos tiros
es de 0.15%
3.2. Cuál es la probabilidad de sacar generala en tres tiros
es de 0.23%
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment