...
1
2
3
4
5 package main
6
7 import (
8 "fmt"
9 "os"
10 )
11
12 var ints = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
13
14 func main() {
15 sum := 0
16 var is []*int
17 for _, i := range ints {
18 for j := 0; j < 10; j++ {
19 if i == j {
20 continue
21 }
22 sum++
23 }
24 if i&1 == 0 {
25 is = append(is, &i)
26 }
27 }
28
29 bug := false
30 if sum != 100-10 {
31 fmt.Printf("wrong sum, expected %d, saw %d\n", 90, sum)
32 bug = true
33 }
34 sum = 0
35 for _, pi := range is {
36 sum += *pi
37 }
38 if sum != 2+4+6+8 {
39 fmt.Printf("wrong sum, expected %d, saw %d\n", 20, sum)
40 bug = true
41 }
42 if !bug {
43 fmt.Printf("PASS\n")
44 } else {
45 os.Exit(11)
46 }
47 }
48
View as plain text