Improve day 13
This commit is contained in:
@@ -81,29 +81,26 @@ func (pair Pair) CheckOrder() bool {
|
|||||||
|
|
||||||
|
|
||||||
func ParseListPacket(listString string) ListPacket {
|
func ParseListPacket(listString string) ListPacket {
|
||||||
|
var j int
|
||||||
packet := ListPacket{[]Packet{}, false}
|
packet := ListPacket{[]Packet{}, false}
|
||||||
|
|
||||||
currI := 1
|
for i := 1; i < len(listString) - 1; i++ {
|
||||||
for i := 1; i < len(listString); i++ {
|
if listString[i] >= '0' && listString[i] <= '9' {
|
||||||
if listString[i] == ',' || listString[i] == ']' {
|
for j = i + 1; listString[j] != ',' && listString[j] != ']'; j++ {}
|
||||||
if listString[currI] >= '0' && listString[currI] <= '9' {
|
convertedInt, _ := strconv.Atoi(listString[i:j])
|
||||||
convertedInt, _ := strconv.Atoi(listString[currI:i])
|
packet.content = append(packet.content, IntPacket(convertedInt))
|
||||||
packet.content = append(packet.content, IntPacket(convertedInt))
|
} else if listString[i] == '[' {
|
||||||
} else if listString[currI] == '[' {
|
depth := 1
|
||||||
depth := 1
|
for j = i + 1; depth != 0; j++ {
|
||||||
var j int
|
if listString[j] == '[' {
|
||||||
for j = currI + 1; depth != 0; j++ {
|
depth++
|
||||||
if listString[j] == '[' {
|
} else if listString[j] == ']' {
|
||||||
depth++
|
depth--
|
||||||
} else if listString[j] == ']' {
|
|
||||||
depth--
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
packet.content = append(packet.content, ParseListPacket(listString[currI:j]))
|
|
||||||
i = j
|
|
||||||
}
|
}
|
||||||
currI = i + 1
|
packet.content = append(packet.content, ParseListPacket(listString[i:j]))
|
||||||
}
|
}
|
||||||
|
i = j
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet
|
return packet
|
||||||
|
|||||||
Reference in New Issue
Block a user