-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (42 loc) · 722 Bytes
/
main.go
File metadata and controls
46 lines (42 loc) · 722 Bytes
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
package main
func fs1(n, repeat int) int {
s := []int{0}
pos := 0
for step := 0; step < repeat; step++ {
for i := 0; i < n; i++ {
pos = (pos + 1) % len(s)
}
if pos == len(s)-1 {
s = append(s, step+1)
} else {
s = insert(s, pos+1, step+1)
}
pos = (pos + 1) % len(s)
}
return s[pos+1]
}
func insert(s []int, i, v int) []int {
res := make([]int, 0, len(s)+1)
for j := 0; j < len(s); j++ {
if j == i {
res = append(res, v)
}
res = append(res, s[j])
}
return res
}
func fs2(n, repeat int) int {
pos := 1
res := -1
for step := 0; step < repeat; step++ {
if step == 0 {
pos = 1
} else {
pos = (pos+n)%(step+1) + 1
}
if pos == 1 {
res = step + 1
}
}
return res
}