Skip to content

Commit 07a76a8

Browse files
committed
part 1 done for day5
1 parent b3dcf6a commit 07a76a8

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

day5/main.go

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ func main() {
1515

1616
input := string(b)
1717

18-
res := startupIntCode(input, 1)
18+
startupIntCode(input, 1)
1919

20-
result := strings.Split(res, ",")
20+
// _ := strings.Split(res, ",")
2121

22-
log.Printf("Output from IntCode computer 🖥 the value of the first output is : %s", result[0])
22+
// log.Printf("Output from IntCode computer 🖥 the value of the first output is : %s", result[0])
2323

2424
}
2525

@@ -35,7 +35,7 @@ func processIntCode(intCodes []string, pInput int) string {
3535
v := intCodes[i]
3636
if len(processCode) > 2 {
3737
if v != "99" {
38-
v = processCode[3:]
38+
v = processCode[len(processCode)-1:]
3939
}
4040

4141
}
@@ -57,24 +57,66 @@ func processIntCode(intCodes []string, pInput int) string {
5757
log.Fatal(err)
5858
}
5959

60-
posRes, err := strconv.Atoi(intCodes[i+4])
61-
if err != nil {
62-
log.Fatal(err)
60+
// posRes, err := strconv.Atoi(intCodes[i+4])
61+
// if err != nil {
62+
// log.Fatal(err)
63+
// }
64+
65+
// log.Printf("v %s , pos1 %d pos2 %d pos3 %d code %s", v, pos1, pos2, pos3, processCode)
66+
67+
v1code := "0"
68+
v2code := "0"
69+
//v3code := "0"
70+
71+
if len(processCode) > 2 {
72+
v1code = string(processCode[0])
73+
if len(processCode) > 3 {
74+
v1code = string(processCode[1])
75+
v2code = string(processCode[0])
76+
}
77+
// if len(processCode) > 4 {
78+
// v3code = processCode[:5]
79+
// }
6380
}
6481

65-
v1, err := strconv.Atoi(intCodes[pos1])
66-
if err != nil {
67-
log.Fatal(err)
82+
// log.Printf("v1code: %s v2code: %s , processcode: %s", v1code, v2code, processCode)
83+
v1 := 0
84+
v2 := 0
85+
if v != "4" && v != "3" {
86+
if v1code != "1" {
87+
v1, err = strconv.Atoi(intCodes[pos1])
88+
if err != nil {
89+
log.Fatal(err)
90+
}
91+
}
92+
if v2code != "1" {
93+
v2, err = strconv.Atoi(intCodes[pos2])
94+
if err != nil {
95+
log.Fatal(err)
96+
}
97+
}
98+
6899
}
69100

70-
v2, err := strconv.Atoi(intCodes[pos2])
71-
if err != nil {
72-
log.Fatal(err)
101+
// v3, err := strconv.Atoi(intCodes[pos3])
102+
// if err != nil {
103+
// log.Fatal(err)
104+
// }
105+
106+
if v1code == "1" {
107+
v1 = pos1
73108
}
74109

75-
log.Printf("v %s , pos1 %d pos2 %d pos3 %d posRes %d", v, pos1, pos2, pos3, posRes)
110+
if v2code == "1" {
111+
v2 = pos2
112+
}
113+
114+
// if v3code == "1" {
115+
// v3 = pos3
116+
// }
76117

77118
if v == "1" {
119+
// log.Printf("v1code %s values %d , %d", v1code, v1, v2)
78120
intCodes[pos3] = strconv.Itoa(v1 + v2)
79121
i += 4
80122
}
@@ -90,8 +132,14 @@ func processIntCode(intCodes []string, pInput int) string {
90132
}
91133

92134
if v == "4" {
135+
// log.Printf("Hmm v1code %s , pos1 %d", v1code, pos1)
93136
i += 2
94-
log.Printf("Output: %s", intCodes[pos1])
137+
if v1code == "1" {
138+
log.Printf("Output: %s", pos1)
139+
} else {
140+
log.Printf("Output: %s", intCodes[pos1])
141+
}
142+
95143
}
96144
}
97145

0 commit comments

Comments
 (0)