Skip to content

Instantly share code, notes, and snippets.

@boris
Created July 7, 2025 20:00
Show Gist options
  • Save boris/8bb28d62c9ddbbbcca6736b2b3a827c9 to your computer and use it in GitHub Desktop.
Save boris/8bb28d62c9ddbbbcca6736b2b3a827c9 to your computer and use it in GitHub Desktop.
Testing
package main
import (
"fmt"
"sort"
)
func transform(nums []int) []int {
// Aquí quizás verificar que el input sea de 10, o de números pares?
evens, odds := make([]int, 0, 5), make([]int, 0, 5)
for _, n := range nums {
if n%2 == 0 {
evens = append(evens, n)
} else {
odds = append(odds, n)
}
}
// Sort de pares e impares
sort.Sort(sort.Reverse(sort.IntSlice(evens))) // desc
sort.Ints(odds) // asc
// Sumar
out := make([]int, 5)
for i := 0; i < 5; i++ {
out[i] = evens[i] + odds[i]
}
return out
}
func main() {
fmt.Println(transform([]int{10, 11, 48, 16, 43, 29, 58, 33, 46, 5}))
fmt.Println(transform([]int{48, 8, 25, 37, 27, 43, 45, 12, 30, 30}))
fmt.Println(transform([]int{47, 32, 5, 49, 37, 60, 13, 40, 38, 22}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment