use x := range and y := range, easier to read.

This commit is contained in:
onyx-and-iris 2025-01-08 05:42:35 +00:00
parent 75d10fffd0
commit 5d6d8fdf79
4 changed files with 12 additions and 12 deletions

View File

@ -17,13 +17,13 @@ func Solve(buf []byte) (int, error) {
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
sumChan := make(chan bool) sumChan := make(chan bool)
for i := 0; i < len(graph.data); i++ { for y := range graph.data {
for j := 0; j < len(graph.data[i]); j++ { for x := range graph.data[y] {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
current := newPoint(j, i) current := newPoint(x, y)
if graph.valueAt(current) == 'X' { if graph.valueAt(current) == 'X' {
for _, n := range neighbours(current) { for _, n := range neighbours(current) {
sumChan <- checkNeighbours(n, "MAS", graph) sumChan <- checkNeighbours(n, "MAS", graph)

View File

@ -16,13 +16,13 @@ func Solve(buf []byte) (int, error) {
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
sumChan := make(chan bool) sumChan := make(chan bool)
for i := 0; i < len(graph.data); i++ { for y := range graph.data {
for j := 0; j < len(graph.data[i]); j++ { for x := range graph.data[y] {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
current := newPoint(j, i) current := newPoint(x, y)
if graph.valueAt(current) == 'A' { if graph.valueAt(current) == 'A' {
if func() bool { if func() bool {
for _, n := range neighbours(current) { for _, n := range neighbours(current) {

View File

@ -15,9 +15,9 @@ func Solve(buf []byte) (int, error) {
var totalCost int var totalCost int
totalAreaVisited := make(map[point]struct{}) totalAreaVisited := make(map[point]struct{})
for i := 0; i < len(graph.data); i++ { for y := range graph.data {
for j := 0; j < len(graph.data[i]); j++ { for x := range graph.data[y] {
start := newPoint(j, i) start := newPoint(x, y)
if graph.isOutOfBounds(start) { if graph.isOutOfBounds(start) {
continue continue
} }

View File

@ -15,9 +15,9 @@ func Solve(buf []byte) (int, error) {
var totalCost int var totalCost int
totalAreaVisited := make(map[point]struct{}) totalAreaVisited := make(map[point]struct{})
for i := 0; i < len(graph.data); i++ { for y := range graph.data {
for j := 0; j < len(graph.data[i]); j++ { for x := range graph.data[y] {
start := newPoint(j, i) start := newPoint(x, y)
if graph.isOutOfBounds(start) { if graph.isOutOfBounds(start) {
continue continue
} }