|
@@ -39,6 +39,81 @@ func minMax(sequence []int) (int, int) {
|
|
return min, max
|
|
return min, max
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func inSequence(value int, sequence []int) bool {
|
|
|
|
+ for _, item := range sequence {
|
|
|
|
+ if item == value {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func indexOf(value int, sequence []int) int {
|
|
|
|
+ for i, item := range sequence {
|
|
|
|
+ if item == value {
|
|
|
|
+ return i
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return -1
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func part1(sequence []int, min, max int) {
|
|
|
|
+ index := 0
|
|
|
|
+
|
|
|
|
+ for i := 0; i < 10; i++ {
|
|
|
|
+ pickup := sequence[index+1 : index+4]
|
|
|
|
+ var partialSequence []int
|
|
|
|
+ for j, item := range sequence {
|
|
|
|
+ if j > index && j < index+4 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ partialSequence = append(partialSequence, item)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ destination := sequence[index] - 1
|
|
|
|
+ fmt.Println(destination)
|
|
|
|
+ for {
|
|
|
|
+ if !inSequence(destination, pickup) {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ destination--
|
|
|
|
+ if destination < min {
|
|
|
|
+ _, newDestination := minMax(partialSequence)
|
|
|
|
+ destination = newDestination
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println(destination)
|
|
|
|
+ destinationIndex := indexOf(destination, partialSequence)
|
|
|
|
+ if destinationIndex < 0 {
|
|
|
|
+ log.Fatalf("Wrong destinationIndex: %d", destinationIndex)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var newSequence []int
|
|
|
|
+ for j, item := range partialSequence {
|
|
|
|
+ newSequence = append(newSequence, item)
|
|
|
|
+
|
|
|
|
+ if j == destinationIndex {
|
|
|
|
+ for _, cup := range pickup {
|
|
|
|
+ newSequence = append(newSequence, cup)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sequence = newSequence
|
|
|
|
+ index++
|
|
|
|
+ if index < 0 {
|
|
|
|
+ index = 0
|
|
|
|
+ }
|
|
|
|
+ fmt.Println(sequence)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
if len(os.Args) < 2 {
|
|
log.Fatal("You need to specify a sequence!")
|
|
log.Fatal("You need to specify a sequence!")
|
|
@@ -47,5 +122,5 @@ func main() {
|
|
sequence := processSequence(os.Args[1])
|
|
sequence := processSequence(os.Args[1])
|
|
min, max := minMax(sequence)
|
|
min, max := minMax(sequence)
|
|
|
|
|
|
- fmt.Println(min, max)
|
|
|
|
|
|
+ part1(sequence, min, max)
|
|
}
|
|
}
|