Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
157 changes: 157 additions & 0 deletions app/src/main/java/com/tamagotchi/code/data/ChallengesData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1394,5 +1394,162 @@ object ChallengesData {
correctAnswerIndex = 0,
explanation = "Las funciones asΓ­ncronas se definen con 'async def'. Dentro de ellas se usa 'await' para llamar a otras funciones asΓ­ncronas."
),
// ========== GO ==========
CodingChallenge(
id = 211,
language = "Go",
type = "TRIVIA",
title = "Arrays vs Slices",
question = "ΒΏCuΓ‘l es la diferencia principal entre un array [3]int y un slice []int en Go?",
options = listOf(
"Son sinΓ³nimos, el compilador los trata igual",
"El array tiene longitud fija y se copia por valor; el slice es una vista dinΓ‘mica sobre un array subyacente",
"El slice solo puede contener enteros, el array cualquier tipo",
"Los arrays se asignan en el heap y los slices en el stack"
),
correctAnswerIndex = 1,
explanation = "En Go, [3]int es un valor de longitud fija que se copia completo al pasarlo a una funciΓ³n. []int es un slice: una estructura (puntero, longitud, capacidad) que apunta a un array subyacente y puede crecer con append()."
),
CodingChallenge(
id = 212,
language = "Go",
type = "PRINT",
title = "Longitud tras append",
question = "ΒΏQuΓ© imprime este cΓ³digo?",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := []int{1, 2, 3}\n\tt := append(s, 4)\n\tfmt.Println(len(s), len(t))\n}",
options = listOf(
"3 4",
"4 4",
"3 3",
"4 3"
),
correctAnswerIndex = 0,
explanation = "append puede reutilizar la capacidad del array subyacente, pero la variable 's' conserva su longitud original (3). El slice devuelto 't' tiene 4 elementos. Salida: '3 4'."
),
CodingChallenge(
id = 213,
language = "Go",
type = "DEBUG",
title = "Variable sin usar",
question = "Este cΓ³digo no compila en Go. ΒΏPor quΓ©?",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tx := 5\n\tfmt.Println(\"listo\")\n}",
options = listOf(
"Falta inicializar x con var",
"Go no permite variables declaradas y nunca usadas; hay que eliminar x o usarla (o asignarla a _)",
"import \"fmt\" debe ir despuΓ©s del main",
":= solo es vΓ‘lido con variables de paquete"
),
correctAnswerIndex = 1,
explanation = "Go es estricto: 'declared and not used: x' es un error de compilaciΓ³n, no un warning. Soluciones tΓ­picas: borrar la variable, usarla, o asignarla al identificador en blanco _."
),
CodingChallenge(
id = 214,
language = "Go",
type = "TRIVIA",
title = "Esperar goroutines",
question = "ΒΏCuΓ‘l es la forma idiomΓ‘tica de esperar a que un grupo de goroutines termine antes de salir del main?",
options = listOf(
"Dormir con time.Sleep(10 * time.Second)",
"Usar sync.WaitGroup: wg.Add(1) antes de lanzar y wg.Done() dentro de cada goroutine, luego wg.Wait()",
"Declarar main como func() error",
"Usar runtime.Goexit() en cada goroutine"
),
correctAnswerIndex = 1,
explanation = "El main termina cuando acaba su funciΓ³n: si lanza goroutines sin sincronizar, pueden no ejecutarse nunca. sync.WaitGroup cuenta las goroutines activas y Wait() bloquea hasta que todas llamen a Done(). Sleep es un antipadrΓ³n: depende del tiempo, no del trabajo real."
),
CodingChallenge(
id = 215,
language = "Go",
type = "PRINT",
title = "Orden de defer",
question = "ΒΏQuΓ© imprime este cΓ³digo?",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tdefer fmt.Println(\"a\")\n\tfmt.Println(\"b\")\n}",
options = listOf(
"a luego b",
"b luego a",
"Solamente b",
"Solamente a"
),
correctAnswerIndex = 1,
explanation = "'defer' pospone la llamada hasta el final de la funciΓ³n circundante: primero se ejecuta Println(\"b\") y, al retornar main, se ejecuta la diferida 'a'. Si hay varios defer, se ejecutan en orden LIFO (pila)."
),
CodingChallenge(
id = 216,
language = "Go",
type = "TRIVIA",
title = "Visibilidad en Go",
question = "En Go, ΒΏcΓ³mo se hace que un identificador (funciΓ³n, struct, campo) sea pΓΊblico/exportado fuera de su paquete?",
options = listOf(
"AΓ±adiendo la palabra clave public",
"Comenzando el nombre con letra mayΓΊscula",
"MarcΓ‘ndolo con el comentario //export",
"DeclarΓ‘ndolo dentro de un bloque exported{}"
),
correctAnswerIndex = 1,
explanation = "Go no tiene modificadores public/private: la visibilidad la decide la primera letra. 'Sumar' es accesible desde otros paquetes; 'sumar' es privado del paquete. Aplica a funciones, tipos, campos y mΓ©todos."
),
CodingChallenge(
id = 217,
language = "Go",
type = "PRINT",
title = "Longitud y capacidad",
question = "ΒΏQuΓ© imprime este cΓ³digo?",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := []int{1, 2, 3, 4}\n\tp := s[1:3]\n\tfmt.Println(len(p), cap(p))\n}",
options = listOf(
"2 2",
"2 3",
"3 3",
"2 4"
),
correctAnswerIndex = 1,
explanation = "p = s[1:3] toma los elementos {2, 3}: longitud 2. Pero la capacidad llega hasta el final del array subyacente: desde el Γ­ndice 1 hay 3 elementos (2, 3, 4), asΓ­ que cap = 3. Por eso append a p puede modificar s[3]."
),
CodingChallenge(
id = 218,
language = "Go",
type = "TRIVIA",
title = "Manejo de errores",
question = "ΒΏCuΓ‘l es la convenciΓ³n idiomatica de manejo de errores en Go?",
options = listOf(
"Lanzar excepciones con try/catch",
"Retornar el error como ΓΊltimo valor y comprobar 'if err != nil' en la llamada",
"Usar cΓ³digos de retorno negativos",
"Registrar el error en un log global y continuar"
),
correctAnswerIndex = 1,
explanation = "Go no usa excepciones para errores recuperables: las funciones devuelven (valor, error) y el llamador inspecciona 'if err != nil { ... }'. Existe panic/recover, pero se reserva para fallos irrecuperables del programa."
),
CodingChallenge(
id = 219,
language = "Go",
type = "PRINT",
title = "Sombras dentro de un bloque",
question = "ΒΏQuΓ© imprime este cΓ³digo?",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tx := 1\n\tif x > 0 {\n\t\tx := 2\n\t\tfmt.Println(x)\n\t}\n\tfmt.Println(x)\n}",
options = listOf(
"1 luego 1",
"2 luego 2",
"2 luego 1",
"Error: redeclaraciΓ³n de x"
),
correctAnswerIndex = 2,
explanation = "'x := 2' dentro del if crea una NUEVA variable que 'sombrea' (shadows) a la exterior solo dentro de ese bloque: imprime 2 dentro y 1 fuera. Ojo con este bug clΓ‘sico al reusar := en lugar de =."
),
CodingChallenge(
id = 220,
language = "Go",
type = "PRINT",
title = "defer con argumentos",
question = "ΒΏQuΓ© imprime este cΓ³digo? (sin salto de lΓ­nea, es un Print)",
codeSnippet = "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfor i := 0; i < 3; i++ {\n\t\tdefer fmt.Print(i)\n\t}\n}",
options = listOf(
"012",
"210",
"222",
"000"
),
correctAnswerIndex = 1,
explanation = "Los argumentos de una llamada diferida se evalΓΊan EN EL MOMENTO del defer (i vale 0, 1, 2), pero las llamadas se ejecutan al final en orden LIFO: 2, 1, 0 β†’ imprime '210'."
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fun TimerPanel(
var tempTopic by remember { mutableStateOf("Kotlin") }
var showDropdown by remember { mutableStateOf(false) }

val topics = listOf("Kotlin", "JavaScript", "PHP", "Python", "SQL", "Clean Code", "Git", "Estructuras de Datos")
val topics = listOf("Kotlin", "JavaScript", "PHP", "Python", "Go", "SQL", "Clean Code", "Git", "Estructuras de Datos")

Column(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ fun BadgesPanel(viewModel: PetViewModel) {
)
Spacer(modifier = Modifier.height(12.dp))

val languages = listOf("Kotlin", "JavaScript", "PHP", "Python")
val languageKeyMap = mapOf("Kotlin" to "KOTLIN", "JavaScript" to "JS", "PHP" to "PHP", "Python" to "PYTHON")
val languages = listOf("Kotlin", "JavaScript", "PHP", "Python", "Go")
val languageKeyMap = mapOf("Kotlin" to "KOTLIN", "JavaScript" to "JS", "PHP" to "PHP", "Python" to "PYTHON", "Go" to "GO")

Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
languages.forEach { langName ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun SettingsLanguageScreen(
stringResource(R.string.topic_data_structures)
)

val allLanguages = listOf("Kotlin", "JavaScript", "Python", "PHP")
val allLanguages = listOf("Kotlin", "JavaScript", "Python", "PHP", "Go")

Scaffold(
containerColor = Color.Transparent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun topicIconRes(topic: String): Int = when {
topic.contains("JavaScript", ignoreCase = true) -> R.drawable.ic_lang_javascript
topic.contains("Python", ignoreCase = true) -> R.drawable.ic_lang_python
topic.contains("PHP", ignoreCase = true) -> R.drawable.ic_lang_php
topic.contains("Go", ignoreCase = true) -> R.drawable.ic_lang_go
topic.contains("SQL", ignoreCase = true) -> R.drawable.ic_lang_sql
topic.contains("Git", ignoreCase = true) -> R.drawable.ic_lang_git
topic.contains("Clean Code", ignoreCase = true) || topic.contains("clean_code", ignoreCase = true) -> R.drawable.ic_lang_cleancode
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_lang_go.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:fillColor="#00ADD8"
android:pathData="M48,24 L208,24 A32,32 0 0,1 240,56 L240,128 L16,128 L16,56 A32,32 0 0,1 48,24 Z M16,144 L240,144 L240,200 A32,32 0 0,1 208,232 L48,232 A32,32 0 0,1 16,200 Z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M78,52 A26,34 0 1,0 78,118 A26,34 0 1,0 78,52 Z M178,52 A26,34 0 1,0 178,118 A26,34 0 1,0 178,52 Z" />
<path
android:fillColor="#0B2B33"
android:pathData="M86,68 A12,16 0 1,0 86,96 A12,16 0 1,0 86,68 Z M186,68 A12,16 0 1,0 186,96 A12,16 0 1,0 186,68 Z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M152,168 L196,168 A28,28 0 0,1 196,220 L152,220 A28,28 0 0,1 152,168 Z M166,182 L184,182 A14,14 0 0,1 184,206 L182,196 L166,196 Z"
android:fillType="evenOdd" />
</vector>
Loading