-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge05.go
61 lines (51 loc) · 897 Bytes
/
challenge05.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"fmt"
"log"
"os"
)
func main() {
f, err := os.ReadFile("mecenas.json")
if err != nil {
log.Fatal(err)
}
mecenas := make([]string, 0)
err = json.Unmarshal(f, &mecenas)
if err != nil {
log.Fatal(err)
}
players := make([]string, len(mecenas))
copy(players, mecenas)
tmp := make([]string, 0)
for i := 0; ; i++ {
if len(players) == 1 {
break
}
if len(players)%2 == 0 {
for idx, p := range players {
if idx%2 == 0 {
tmp = append(tmp, p)
}
}
} else {
for idx, p := range players {
if idx == 0 {
continue
}
if idx%2 == 0 {
tmp = append(tmp, p)
}
}
}
players = tmp
tmp = tmp[:0]
}
idxs := make([]int, 0)
for idx, m := range mecenas {
if m == players[0] {
idxs = append(idxs, idx)
}
}
fmt.Printf("Mecena survivor: %+v, and it indexes: %+v\n", players, idxs)
}