:work: Working with part 2 of day 7
This commit is contained in:
parent
0b74b2411b
commit
1594ddd9ab
50
day7/main.go
50
day7/main.go
@ -92,7 +92,7 @@ func RunAmplification(list []int, phases []int) int {
|
|||||||
inputs = append(inputs, inputStr)
|
inputs = append(inputs, inputStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err, _ := ParseArray(wip, inputs)
|
output, err, _, _ := ParseArray(wip, inputs, 0)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Problem at Amplification: %d", i+1)
|
log.Printf("Problem at Amplification: %d", i+1)
|
||||||
@ -109,17 +109,15 @@ func RunRecursiveAmplification(list []int, phases []int) int {
|
|||||||
signal := []string{"0"}
|
signal := []string{"0"}
|
||||||
|
|
||||||
amplifier := make([][]int, 0)
|
amplifier := make([][]int, 0)
|
||||||
|
startIndex := make([]int, 0)
|
||||||
|
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
log.Println("============")
|
|
||||||
log.Println(i)
|
|
||||||
if len(amplifier) <= i {
|
if len(amplifier) <= i {
|
||||||
log.Println(len(amplifier))
|
log.Println("APPPEND")
|
||||||
wip := make([]int, len(list))
|
wip := make([]int, len(list))
|
||||||
copy(wip, list)
|
copy(wip, list)
|
||||||
amplifier = append(amplifier, wip)
|
amplifier = append(amplifier, wip)
|
||||||
log.Println(len(amplifier))
|
startIndex = append(startIndex, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs := make([]int, 0)
|
inputs := make([]int, 0)
|
||||||
@ -129,7 +127,8 @@ func RunRecursiveAmplification(list []int, phases []int) int {
|
|||||||
inputs = append(inputs, inputStr)
|
inputs = append(inputs, inputStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err, cmdSuccess := ParseArray(amplifier[i], inputs)
|
output, err, cmdSuccess, ind := ParseArray(amplifier[i], inputs, startIndex[i])
|
||||||
|
startIndex[i] = ind
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Problem at Amplification: %d", i+1)
|
log.Printf("Problem at Amplification: %d", i+1)
|
||||||
@ -138,19 +137,20 @@ func RunRecursiveAmplification(list []int, phases []int) int {
|
|||||||
|
|
||||||
signal = output
|
signal = output
|
||||||
|
|
||||||
if cmdSuccess {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if i == 4 {
|
if i == 4 {
|
||||||
i = -1
|
i = -1
|
||||||
|
|
||||||
|
if cmdSuccess {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sigInt, _ := strconv.Atoi(signal[len(signal)-1])
|
sigInt, _ := strconv.Atoi(signal[len(signal)-1])
|
||||||
|
fmt.Println(len(signal))
|
||||||
return sigInt
|
return sigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseArray(list []int, inputs []int) ([]string, error, bool) {
|
func ParseArray(list []int, inputs []int, startIndex int) ([]string, error, bool, int) {
|
||||||
var (
|
var (
|
||||||
output []string
|
output []string
|
||||||
)
|
)
|
||||||
@ -158,14 +158,11 @@ func ParseArray(list []int, inputs []int) ([]string, error, bool) {
|
|||||||
inputIndex := 0
|
inputIndex := 0
|
||||||
output = make([]string, 0)
|
output = make([]string, 0)
|
||||||
|
|
||||||
for i := 0; i < len(list); i += 4 {
|
log.Println("=================")
|
||||||
//log.Println(strconv.Itoa(i) + " -> " + strconv.Itoa(list[i]))
|
for i := startIndex; i < len(list); i += 4 {
|
||||||
|
log.Println(strconv.Itoa(i) + " -> " + strconv.Itoa(list[i]))
|
||||||
cmd := list[i]
|
cmd := list[i]
|
||||||
|
|
||||||
if cmd == 99 {
|
|
||||||
return output, nil, true
|
|
||||||
}
|
|
||||||
|
|
||||||
sum := 0
|
sum := 0
|
||||||
|
|
||||||
mode1 := 0
|
mode1 := 0
|
||||||
@ -188,6 +185,10 @@ func ParseArray(list []int, inputs []int) ([]string, error, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd == 99 {
|
||||||
|
return output, nil, true, -2
|
||||||
|
}
|
||||||
|
|
||||||
if cmd == 1 {
|
if cmd == 1 {
|
||||||
num1 := -1
|
num1 := -1
|
||||||
num2 := -1
|
num2 := -1
|
||||||
@ -226,10 +227,7 @@ func ParseArray(list []int, inputs []int) ([]string, error, bool) {
|
|||||||
inputIndex++
|
inputIndex++
|
||||||
list[list[i+1]] = input
|
list[list[i+1]] = input
|
||||||
} else {
|
} else {
|
||||||
input := output[0]
|
return output, nil, false, i
|
||||||
output = output[1:]
|
|
||||||
inputInt, _ := strconv.Atoi(input)
|
|
||||||
list[list[i+1]] = inputInt
|
|
||||||
}
|
}
|
||||||
i = i - 2
|
i = i - 2
|
||||||
} else if cmd == 4 {
|
} else if cmd == 4 {
|
||||||
@ -312,16 +310,12 @@ func ParseArray(list []int, inputs []int) ([]string, error, bool) {
|
|||||||
list[list[i+3]] = 0
|
list[list[i+3]] = 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return output, errors.New("Wrong Command (" + strconv.Itoa(list[i]) + ") at position " + strconv.Itoa(i)), false
|
return output, errors.New("Wrong Command (" + strconv.Itoa(list[i]) + ") at position " + strconv.Itoa(i)), false, -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(inputs) > inputIndex {
|
|
||||||
output = append(strings.Fields(fmt.Sprint(inputs[inputIndex:])), output...)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("NONE")
|
log.Println("NONE")
|
||||||
return output, nil, false
|
return output, nil, false, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func CountDigits(i int) int {
|
func CountDigits(i int) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user