Skip to content

Instantly share code, notes, and snippets.

@ceaksan
Created March 6, 2018 18:25
Show Gist options
  • Save ceaksan/f8d439333fc8e8d6feac3ee8370eae03 to your computer and use it in GitHub Desktop.
Save ceaksan/f8d439333fc8e8d6feac3ee8370eae03 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
var (
coins = 50
users = []string{
"Matthew", "Sarah", "Augustus", "Heidi", "Emilie",
"Peter", "Giana", "Adriano", "Aaron", "Elizabeth",
}
distribution = make(map[string]int, len(users))
)
func main() {
for _, userName := range users {
var total int
for i := 0; i < len(userName); i++ {
switch string(userName[i]) {
case "A", "a", "E", "e": // or case 65, 97, 69, 101:
total++
case "I", "ı", "İ", "i": // or 73, 177, 176, 105:
total = total + 2
case "O", "o", "Ö", "ö": // or 79, 111, 150, 182:
total = total + 3
case "U", "u", "Ü", "ü": // or 85, 117, 156, 188:
total = total + 4
}
}
if total > 10 {
total = 10
}
coins = coins - total
distribution[userName] = total
}
fmt.Println(distribution)
fmt.Println("Coins left:", coins)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment