diff --git b/Tarea_1/.idea/.gitignore a/Tarea_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ a/Tarea_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git b/Tarea_1/.idea/kotlinc.xml a/Tarea_1/.idea/kotlinc.xml new file mode 100644 index 0000000..d79fd11 --- /dev/null +++ a/Tarea_1/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git b/Tarea_1/.idea/libraries/KotlinJavaRuntime.xml a/Tarea_1/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..1a7265d --- /dev/null +++ a/Tarea_1/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git b/Tarea_1/.idea/libraries/KotlinJavaRuntime__2_.xml a/Tarea_1/.idea/libraries/KotlinJavaRuntime__2_.xml new file mode 100644 index 0000000..4520532 --- /dev/null +++ a/Tarea_1/.idea/libraries/KotlinJavaRuntime__2_.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git b/Tarea_1/.idea/misc.xml a/Tarea_1/.idea/misc.xml new file mode 100644 index 0000000..40674af --- /dev/null +++ a/Tarea_1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git b/Tarea_1/.idea/modules.xml a/Tarea_1/.idea/modules.xml new file mode 100644 index 0000000..a8366d6 --- /dev/null +++ a/Tarea_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git b/Tarea_1/.idea/vcs.xml a/Tarea_1/.idea/vcs.xml new file mode 100644 index 0000000..1b2a650 --- /dev/null +++ a/Tarea_1/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git b/Tarea_1/Tarea_1.iml a/Tarea_1/Tarea_1.iml new file mode 100644 index 0000000..af33657 --- /dev/null +++ a/Tarea_1/Tarea_1.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio10.kt a/Tarea_1/src/main/kotlin/ejercicio10.kt new file mode 100644 index 0000000..b36d229 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio10.kt @@ -0,0 +1,24 @@ +//Ejercicio 10 + +fun main(){ + + println(contarValoresUnicos(listOf(2,3,4,5,6,2,2,3))) +} + +fun contarValoresUnicos(lista : List): Int{ + //por implementacion + var rep : Boolean = true + var cant : Int = 1 + for (i in 1 until lista.size){ + rep = true + for(k in i-1 downTo 0){ + if(lista[i]==lista[k]){ + rep =false + } + } + if(rep){ + cant++ + } + } + return cant +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio11.kt a/Tarea_1/src/main/kotlin/ejercicio11.kt new file mode 100644 index 0000000..ff6cacc --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio11.kt @@ -0,0 +1,20 @@ +//Ejercicio 11 + +fun main(){ + println(top2PalabrasLargas("Hola que tal estas amigo")) +} + +fun top2PalabrasLargas(cadena : String): List { + var partes = cadena.split(" ") + var mayor1 = partes[0] + var mayor2 = partes[0] + for( i in partes){ + if(i.length>mayor1.length){ + mayor2=mayor1 + mayor1=i + }else if(i.length>mayor2.length){ + mayor2=i + } + } + return listOf(mayor1,mayor2) +} diff --git b/Tarea_1/src/main/kotlin/ejercicio12.kt a/Tarea_1/src/main/kotlin/ejercicio12.kt new file mode 100644 index 0000000..d2bd8b6 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio12.kt @@ -0,0 +1,11 @@ +//Ejercicio 12 + +fun main(){ + println(esPalindromo("abBA")) +} + +//Ejercicio 12 +fun esPalindromo(cadena: String):Boolean{ + return cadena.equals(cadena.reversed(), ignoreCase = true) +} + diff --git b/Tarea_1/src/main/kotlin/ejercicio13.kt a/Tarea_1/src/main/kotlin/ejercicio13.kt new file mode 100644 index 0000000..02e7d07 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio13.kt @@ -0,0 +1,25 @@ +//Ejercicio 13 + +fun main(){ + + println(esPalindromo2("awba")) + println(esPalindromo2("a@abaa")) +} + +//Ejercicio 13 +fun esPalindromo2(cadena: String):Boolean{ + var cad : String = "" + var error : Int = 0 + var cont : Int =0 + for (i in cadena.indices){ + cad="" + for (k in cadena.indices){ + if(i==k) continue + cad+=cadena[k] + } + if(esPalindromo(cad)){ + return true + } + } + return false +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio14.kt a/Tarea_1/src/main/kotlin/ejercicio14.kt new file mode 100644 index 0000000..4e965b4 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio14.kt @@ -0,0 +1,16 @@ +//Ejercicio 14 + +fun main(){ + println(contarVocales("hola viejos")) +} + +fun contarVocales(cadena:String): Int{ + val vocales : String="aeiou" + var cant : Int = 0 + for(letra in cadena){ + if(vocales.contains(letra)){ + cant++ + } + } + return cant +} diff --git b/Tarea_1/src/main/kotlin/ejercicio15.kt a/Tarea_1/src/main/kotlin/ejercicio15.kt new file mode 100644 index 0000000..448530a --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio15.kt @@ -0,0 +1,22 @@ +//Ejercicio 15 + +fun main(){ + println(cifrar("zzz",2)) +} + +fun cifrar (cadena:String, desplazamiento:Int):String{ + var codigo :String ="" + var pos : Int =0 + val letras : String = "abcdefghijklmnopqrstuvwxyz" + var cod = desplazamiento%letras.length + for (i in cadena){ + pos=letras.indexOf(i) + if(pos+cod>=letras.length){ + pos=cod-1 + }else{ + pos+=cod + } + codigo+="${letras[pos]}" + } + return codigo +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio16.kt a/Tarea_1/src/main/kotlin/ejercicio16.kt new file mode 100644 index 0000000..16e2533 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio16.kt @@ -0,0 +1,22 @@ +//Ejercicio 16 + +fun main(){ + println(descrifrar("aaa",52)) +} + +fun descrifrar(cadena: String, desplazamiento: Int):String{ + var codigo :String ="" + var pos : Int =0 + val letras : String = "abcdefghijklmnopqrstuvwxyz" + var cod = desplazamiento % letras.length + for (i in cadena){ + pos=letras.indexOf(i) + if(pos-cod<0){ + pos=letras.length-cod + }else{ + pos-=cod + } + codigo+="${letras[pos]}" + } + return codigo +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio3.kt a/Tarea_1/src/main/kotlin/ejercicio3.kt new file mode 100644 index 0000000..5cf6245 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio3.kt @@ -0,0 +1,18 @@ +//Ejercicio 3 + +fun main(){ + val N =5 + println(sumaFilaNrosImpares(N)) +} + +fun sumaFilaNrosImpares(N:Int):Int{ + var inicio =1 + var sum =0 + for(i in 2..N){ + inicio+=2*(i-1) + } + for (k in 1..N){ + sum+= inicio+2*(k-1) + } + return sum +} diff --git b/Tarea_1/src/main/kotlin/ejercicio4.kt a/Tarea_1/src/main/kotlin/ejercicio4.kt new file mode 100644 index 0000000..c58bf00 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio4.kt @@ -0,0 +1,26 @@ +//Ejercicio 4 + +fun main(){ + + println(capitalizarTexto("hola que tal")) + println(capitalizarTexto("Hola Que Tal")) +} + +fun capitalizarTexto(cadena:String) :String { + //por funciones cadena.capitalize() + //por implementacion + var cad : String = "" + var bandera =1 + for(i in cadena){ + if(' ' == i){ + cad+="$i" + bandera=1 + }else if(bandera==1 && i!=' '){ + cad +="${i.toUpperCase()}" + bandera = 0 + }else{ + cad+="$i" + } + } + return cad +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio5.kt a/Tarea_1/src/main/kotlin/ejercicio5.kt new file mode 100644 index 0000000..14cf51a --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio5.kt @@ -0,0 +1,19 @@ +//Ejercicio 5 + +fun main(){ + println("${obtenerImpares(listOf(2,3,4,5,6))}") +} + +fun obtenerImpares(lista: List) : Int?{ + var cant : Int =0 + for(i in lista){ + if(i%2!=0){ + cant++ + } + } + return if(cant==0){ + null + }else { + cant + } +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio6.kt a/Tarea_1/src/main/kotlin/ejercicio6.kt new file mode 100644 index 0000000..2bc8381 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio6.kt @@ -0,0 +1,13 @@ +//Ejercicio 6 + +fun main(){ + println(sumarHasta(4)) +} +fun sumarHasta(n:Int) :Int{ + var suma=0 + for(i in 1..n){ + suma+=i + } + return suma +} + diff --git b/Tarea_1/src/main/kotlin/ejercicio7.kt a/Tarea_1/src/main/kotlin/ejercicio7.kt new file mode 100644 index 0000000..9179e39 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio7.kt @@ -0,0 +1,12 @@ +//Ejercicio 7 + +fun main(){ + cuentaRegresiva(5) +} + +fun cuentaRegresiva(n:Int) { + for(i in n downTo 0){ + print("$i ") + } + print("\n") +} diff --git b/Tarea_1/src/main/kotlin/ejercicio8.kt a/Tarea_1/src/main/kotlin/ejercicio8.kt new file mode 100644 index 0000000..5feced2 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio8.kt @@ -0,0 +1,14 @@ +//Ejercicio 8 + +fun main(){ + + contar(5) +} + +fun contar(n:Int){ + cuentaRegresiva(n) + for(i in 0..n){ + print("$i") + } + print("\n") +} \ No newline at end of file diff --git b/Tarea_1/src/main/kotlin/ejercicio9.kt a/Tarea_1/src/main/kotlin/ejercicio9.kt new file mode 100644 index 0000000..19262f5 --- /dev/null +++ a/Tarea_1/src/main/kotlin/ejercicio9.kt @@ -0,0 +1,23 @@ +//Ejercicio 9 + +fun main(){ + llamarLista(listOf("Juan","Pablo","Ruben")) + llamarLista(listOf("Rossana")) +} + +fun llamarLista(lista: List) { + print("Llamando lista a ") + if(lista.size == 1){ + print(lista[0]) + } + for((index,nombre) in lista.withIndex()){ + if(index) { + + +} + + + +//Ejercicio 16