remove ugly tmp struct
This commit is contained in:
parent
d529b002b4
commit
4e64387873
43
03/main.go
43
03/main.go
@ -40,11 +40,6 @@ type entry struct {
|
|||||||
symb rune
|
symb rune
|
||||||
}
|
}
|
||||||
|
|
||||||
type tmp struct {
|
|
||||||
tmp []rune
|
|
||||||
col int
|
|
||||||
}
|
|
||||||
|
|
||||||
type coord struct {
|
type coord struct {
|
||||||
row int
|
row int
|
||||||
col int
|
col int
|
||||||
@ -65,20 +60,15 @@ func partOne() {
|
|||||||
// read the whole thing in
|
// read the whole thing in
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
i := tmp{}
|
acc := []rune{}
|
||||||
for col, c := range line {
|
for col, c := range line {
|
||||||
switch c {
|
switch c {
|
||||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
||||||
if len(i.tmp) == 0 {
|
acc = append(acc, c)
|
||||||
i.tmp = append(i.tmp, c)
|
|
||||||
i.col = col
|
|
||||||
} else {
|
|
||||||
i.tmp = append(i.tmp, c)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if len(i.tmp) != 0 {
|
if len(acc) != 0 {
|
||||||
schematic[coord{row, i.col}] = entry{num: i.tmp}
|
schematic[coord{row, col - len(acc)}] = entry{num: acc}
|
||||||
i.tmp = []rune{}
|
acc = []rune{}
|
||||||
}
|
}
|
||||||
if c != '.' {
|
if c != '.' {
|
||||||
schematic[coord{row, col}] = entry{symb: c}
|
schematic[coord{row, col}] = entry{symb: c}
|
||||||
@ -86,8 +76,8 @@ func partOne() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if we have a number still to save but ran out of line
|
// check if we have a number still to save but ran out of line
|
||||||
if len(i.tmp) != 0 {
|
if len(acc) != 0 {
|
||||||
schematic[coord{row, i.col}] = entry{num: i.tmp}
|
schematic[coord{row, len(line) - len(acc)}] = entry{num: acc}
|
||||||
}
|
}
|
||||||
row++
|
row++
|
||||||
}
|
}
|
||||||
@ -128,20 +118,15 @@ func partTwo() {
|
|||||||
// read the whole thing in
|
// read the whole thing in
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
i := tmp{}
|
acc := []rune{}
|
||||||
for col, c := range line {
|
for col, c := range line {
|
||||||
switch c {
|
switch c {
|
||||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
||||||
if len(i.tmp) == 0 {
|
acc = append(acc, c)
|
||||||
i.tmp = append(i.tmp, c)
|
|
||||||
i.col = col
|
|
||||||
} else {
|
|
||||||
i.tmp = append(i.tmp, c)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if len(i.tmp) != 0 {
|
if len(acc) != 0 {
|
||||||
schematic[coord{row, i.col}] = entry{num: i.tmp}
|
schematic[coord{row, col - len(acc)}] = entry{num: acc}
|
||||||
i.tmp = []rune{}
|
acc = []rune{}
|
||||||
}
|
}
|
||||||
if c == '*' { // no longer care about other symbols
|
if c == '*' { // no longer care about other symbols
|
||||||
schematic[coord{row, col}] = entry{symb: c}
|
schematic[coord{row, col}] = entry{symb: c}
|
||||||
@ -149,8 +134,8 @@ func partTwo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if we have a number still to save but ran out of line
|
// check if we have a number still to save but ran out of line
|
||||||
if len(i.tmp) != 0 {
|
if len(acc) != 0 {
|
||||||
schematic[coord{row, i.col}] = entry{num: i.tmp}
|
schematic[coord{row, len(line) - len(acc)}] = entry{num: acc}
|
||||||
}
|
}
|
||||||
row++
|
row++
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user