refactoring: just better naming
This commit is contained in:
@@ -17,7 +17,7 @@ func ParseInput(filepath string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type instruction struct {
|
type instruction struct {
|
||||||
op string
|
operation string
|
||||||
x1, y1 int
|
x1, y1 int
|
||||||
x2, y2 int
|
x2, y2 int
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func parseInstruction(line string) (instruction, bool) {
|
|||||||
x2, _ := strconv.Atoi(secondCoordinates[0])
|
x2, _ := strconv.Atoi(secondCoordinates[0])
|
||||||
y2, _ := strconv.Atoi(secondCoordinates[1])
|
y2, _ := strconv.Atoi(secondCoordinates[1])
|
||||||
|
|
||||||
return instruction{op: op, x1: x1, y1: y1, x2: x2, y2: y2}, true
|
return instruction{operation: op, x1: x1, y1: y1, x2: x2, y2: y2}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func PartOne(data []string) int {
|
func PartOne(data []string) int {
|
||||||
@@ -64,7 +64,7 @@ func PartOne(data []string) int {
|
|||||||
for y := instruction.y1; y <= instruction.y2; y++ {
|
for y := instruction.y1; y <= instruction.y2; y++ {
|
||||||
for x := instruction.x1; x <= instruction.x2; x++ {
|
for x := instruction.x1; x <= instruction.x2; x++ {
|
||||||
idx := y*1000 + x
|
idx := y*1000 + x
|
||||||
switch instruction.op {
|
switch instruction.operation {
|
||||||
case "on":
|
case "on":
|
||||||
grid[idx] = true
|
grid[idx] = true
|
||||||
case "off":
|
case "off":
|
||||||
@@ -89,15 +89,15 @@ func PartTwo(data []string) int {
|
|||||||
grid := make([]int, 1000*1000)
|
grid := make([]int, 1000*1000)
|
||||||
|
|
||||||
for _, line := range data {
|
for _, line := range data {
|
||||||
inst, ok := parseInstruction(line)
|
instruction, ok := parseInstruction(line)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for y := inst.y1; y <= inst.y2; y++ {
|
for y := instruction.y1; y <= instruction.y2; y++ {
|
||||||
for x := inst.x1; x <= inst.x2; x++ {
|
for x := instruction.x1; x <= instruction.x2; x++ {
|
||||||
idx := y*1000 + x
|
idx := y*1000 + x
|
||||||
switch inst.op {
|
switch instruction.operation {
|
||||||
case "on":
|
case "on":
|
||||||
grid[idx]++
|
grid[idx]++
|
||||||
case "off":
|
case "off":
|
||||||
|
|||||||
Reference in New Issue
Block a user