-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstitem.go
46 lines (41 loc) · 954 Bytes
/
firstitem.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
package firstitem
import (
"strconv"
)
func FirstItemBefore(a int) (l int) {
res := []string{"1"}
for i := 2; i < 1000; i++ {
res = append(res, "+")
res = append(res, strconv.Itoa(i))
}
return len(res)
}
func FirstItemIfOnIndex(a int) (l int) {
res := make([]string, 0)
for i := 1; i < a; i++ {
if i != 1 { // specific treatment
res = append(res, "+")
}
res = append(res, strconv.Itoa(i))
}
return len(res)
}
func FirstItemIfOnArray(a int) (l int) {
res := make([]string, 0)
for i := 1; i < a; i++ {
if len(res) != 0 { // specific treatment
res = append(res, "+")
}
res = append(res, strconv.Itoa(i))
}
return len(res)
}
func FirstItemBeforeUnfair(a int) (l int) {
res := []string{"1"}
for i := 2; i < a; i++ {
// This is not representative as the hypothesis implies that the first
// item has some complex treatment creating code duplication.
res = append(res, "+", strconv.Itoa(i))
}
return len(res)
}