vkorbes / aprendago

Curso completo em português da linguagem Go, de zero a ninja! 🇧🇷
http://aprendago.com
1.05k stars 184 forks source link

Exercício: Capítulo 17, Exercício 4 (Nível: 8) #57

Open vkorbes opened 4 years ago

vkorbes commented 4 years ago

Exercício: Capítulo 17, Exercício 4 (Nível: 8)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

an4kein commented 3 years ago

https://play.golang.org/p/WrsSododUgM

package main

/* - Partindo do código abaixo, ordene a []int e a []string.
   - https://play.golang.org/p/H_q75mpmHW */

import (
    "fmt"
    "sort"
)

func main() {
    xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
    xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}

    fmt.Println(xi)
    // sort xi
    sort.Ints(xi)
    fmt.Println(xi)

    fmt.Println(xs)
    // sort xs
    sort.Strings(xs)
    fmt.Println(xs)
}

Output

[5 8 2 43 17 987 14 12 21 1 4 2 3 93 13]
[1 2 2 3 4 5 8 12 13 14 17 21 43 93 987]
[random rainbow delights in torpedo summers under gallantry fragmented moons across magenta]
[across delights fragmented gallantry in magenta moons rainbow random summers torpedo under]

Program exited.
alansantosmg commented 3 years ago

My solution:

package main

import (
    "fmt"
    "sort"
)

func main() {
    xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
    xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}

    fmt.Println(xi)
    // sort xi
    sort.Ints(xi)
    fmt.Println(xi)

    fmt.Println(xs)
    // sort xs
    sort.Strings(xs)
    fmt.Println(xs)
}
wfrsilva commented 2 years ago

Cap. 17 – Exercícios: Nível #8 – 4 https://go.dev/play/p/I1pY8TlIpzp

image

Harsgaard commented 1 year ago

https://go.dev/play/p/dCgrqQNbqzn

LelecoNN commented 1 year ago

https://go.dev/play/p/M8FDdKE-t6l

package main

import (
    "fmt"
    "sort"
)

func main() {
    xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
    xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}

    fmt.Println(xi)
    // sort xi
    sort.Ints(xi)
    fmt.Println(xi)

    fmt.Println(xs)
    // sort xs
    sort.Strings(xs)
    fmt.Println(xs)
}