-
Notifications
You must be signed in to change notification settings - Fork 0
/
advent14-1.go
72 lines (49 loc) · 1.22 KB
/
advent14-1.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
package main
import("fmt";"bufio";"os";"strings")
func main(){
fmt.Println("Input coordinates:")
reader:= bufio.NewReader(os.Stdin)
var sat []string
for{
s,_ := reader.ReadString('\n')
s=strings.TrimSpace(s)
if(s=="end"){break}
sat = append(sat,s)
}
sat = north(sat)
fmt.Println(len(sat))
w := len(sat)
weight:=0
for _,ss := range sat{
for _,c := range ss{
if(c=='O'){
weight = weight+w
}
}
w--
}
fmt.Println("North weight:",weight)
}
func north(ss []string) []string{
for i,s := range ss{
for j,c:= range s{
if(c=='O'){
l := i
for k:=i-1;k>=0;k--{
if(ss[k][j]=='.'){
b := []byte(ss[k])
b[j] = 'O'
ss[k] = string(b)
b = []byte(ss[l])
b[j] = '.'
ss[l] = string(b)
l = l-1
}else{
break
}
}
}
}
}
return ss
}