aboutsummaryrefslogtreecommitdiff
path: root/2019/go/day03.go
blob: 2c79a18cba0dfd38865b69da878a3fc68640da3b (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	var directions [][]string
	var temp []string
	start := 0

	if len(os.Args) < 2 {
		panic("runtime error: missing operand")
	}
	file, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		panic(err)
	}
	for i := 0; i < len(file); i++ {
		if string(file[i]) == "," || file[i] == '\n' {
			temp = append(temp, string(file[start:i]))
			start = i + 1
			if file[i] == '\n' {
				directions[] = append(directions[], temp)
				temp = nil
			}
		}
	}
	fmt.Println(directions)

	// grid [][]int := boolgrid(directions)

}

// 	ax, ay, at := taxi(directions[0])
// 	bx, by, bt := taxi(directions[1])
// 	for i := 0; i < at; i++ {
// 		for j := 0; j < at; j++ {
// 			for k := 0; k <
// 			ax[i][j]
// 		}
// 	}
// 	abx, aby

// 	grid = taxi(directions, taxi(directions2, grid))
// 	min, x, y := 4000, 0, 0
// 	for i := 0; i < len(grid); i++ {
// 		for j := 0; j < len(grid); j++ {
// 			x, y = int(math.Abs(float64(i-500))), int(math.Abs(float64(j-500)))
// 			if grid[i][j] == 2 && x+y < min {
// 				fmt.Println(i-500, j-500)
// 				min = x + y
// 			}

// 		}
// 	}
// 	fmt.Println("Manhattan distance to intersection:", min)
// }

// func taxi(directions []string) ([]int, []int, int) {
// 	var horislice, vertslice []int
// 	total := 0
// 	for i := 0; i < len(directions); i++ {
// 		direction := directions[i][0]
// 		displacement, err := strconv.Atoi(directions[i][1:])
// 		if err != nil {
// 			panic(err)
// 		}
// 		switch direction {
// 		case 'L':
// 			for j := 0; j < displacement; j++ {
// 				horislice = append(horislice, horislice[total]-j)
// 				vertslice = append(vertslice, vertslice[total])
// 				total++
// 			}
// 		case 'R':
// 			for j := 0; j < displacement; j++ {
// 				horislice = append(horislice, horislice[total]+j)
// 				vertslice = append(vertslice, vertslice[total])
// 				total++
// 			}
// 		case 'U':
// 			for j := 0; j < displacement; j++ {
// 				vertslice = append(vertslice, vertslice[total]+j)
// 				horislice = append(horislice, horislice[total])
// 				total++
// 			}
// 		case 'D':
// 			for j := 0; j < displacement; j++ {
// 				vertslice = append(vertslice, vertslice[total]-j)
// 				horislice = append(horislice, horislice[total])
// 				total++
// 			}
// 		default:
// 			fmt.Println("Unhandled direction", string(direction))
// 			os.Exit(0)
// 		}
// 	}
// 	return horislice, vertslice, total
// }

// func taxi(directions []string, grid [4000][4000]int) [4000][4000]int { // sign convention: an array, left to right, top to bottom, beginning in the top left corner
// 	x, y := len(grid)/2, len(grid[0])/2 // start in center
// 	var boolgrid [4000][4000]bool
// 	for i := 0; i < len(directions); i++ {
// 		direction := directions[i][0]
// 		displacement, err := strconv.Atoi(directions[i][1:])
// 		if err != nil {
// 			panic(err)
// 		}
// 		switch direction {
// 		case 'L':
// 			for j := 0; j < displacement; j++ {
// 				x--
// 				if !boolgrid[x][y] {
// 					boolgrid[x][y] = true
// 				}
// 			}
// 		case 'R':
// 			for j := 0; j < displacement; j++ {
// 				x++
// 				if !boolgrid[x][y] {
// 					boolgrid[x][y] = true
// 				}
// 			}
// 		case 'U':
// 			for j := 0; j < displacement; j++ {
// 				y--
// 				if !boolgrid[x][y] {
// 					boolgrid[x][y] = true
// 				}
// 			}
// 		case 'D':
// 			for j := 0; j < displacement; j++ {
// 				y++
// 				if !boolgrid[x][y] {
// 					boolgrid[x][y] = true
// 				}
// 			}
// 		default:
// 			fmt.Println("Unhandled direction", string(direction))
// 			os.Exit(0)
// 		}
// 		fmt.Println(string(direction), displacement, x, y)
// 	}
// 	for i := 0; i < len(grid); i++ {
// 		for j := 0; j < len(grid[0]); j++ {
// 			if boolgrid[i][j] {
// 				grid[i][j]++
// 			}
// 		}
// 	}
// 	return grid // each element is equal to the numbers of wires on it
// }