-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvent12-2.go
125 lines (110 loc) · 3.16 KB
/
advent12-2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import("fmt";"bufio";"os";"strings";"strconv")
//var level = 0
func main(){
fmt.Println("[This works but it takes infinity years]")
fmt.Println("Input springs:")
counttot := 0
reader:= bufio.NewReader(os.Stdin)
for{
s,_ := reader.ReadString('\n')
s=strings.TrimSpace(s)
if(s=="end"){break}
var nums1 []int
ss := strings.Split(s," ")
springs1 := ss[0]
ss2 := strings.Split(ss[1],",")
for _,i := range ss2{
ii,_ := strconv.Atoi(i)
nums1 = append(nums1,ii)
}
var springs = springs1
var nums []int
for _,n := range nums1{
nums = append(nums,n)
}
for i:=0;i<4;i++{
springs = strings.Join([]string{springs,springs1},"?")
for _,n := range nums1{
nums = append(nums,n)
}
}
fmt.Println(springs,nums)
var sp1 string
var myst []int
for i,c := range springs{
if(c=='?'){
myst = append(myst,i)
sp1 = strings.Join([]string{sp1,"#"},"")
}else{
sp1 = strings.Join([]string{sp1,string(c)},"")
}
}
var strops []string
strops = append(strops,sp1)
strops = apper(sp1,strops,0,myst)
//fmt.Println(strops)
countsame := 0
for _,s := range strops{
ints := count(s)
//fmt.Println(s,ints)
if(len(ints)==len(nums)){
same := 1
for i,_ := range ints{
if(ints[i]!=nums[i]){
same=0
break
}
}
if(same==1){
//fmt.Println(s,springs,nums,"They are the same")
countsame++
}else{}//fmt.Println(s,springs,nums,"They are not the same")}
}
}
fmt.Println("Same",countsame)
counttot = counttot + countsame
}
fmt.Println("Tot Same",counttot)
}
func count(s string) []int{
var ints []int
counter:=0
for _,c := range s{
if(c=='#'){
counter++
}else if(c=='.'){
if(counter>0){ints = append(ints,counter)}
counter=0
}
}
if(s[len(s)-1]=='#'){ints=append(ints,counter)}
return ints
}
func apper(sp1 string, ss []string, ii int, myst []int) []string{
var sp string
for i:=ii;i<len(myst);i++{
sp2 := sp1
sp = ""
focus := myst[i]
// for z:=0;z<level;z++{
// fmt.Printf("\t")
// }
// fmt.Printf("%d[%d]\t",level,focus)
for j,c := range sp2{
if(j!=focus){
sp = strings.Join([]string{sp,string(c)},"")
}else{
sp = strings.Join([]string{sp,"."},"")
}
}
//fmt.Printf("%s\n",sp)
ss = append(ss,sp)
if(i+1<len(myst)){
//level++
ss = apper(sp,ss,i+1,myst)
//level--
}
}
return ss
}