@@ -29,19 +29,19 @@ func main() {
2929 }
3030 if str := dispersion (positions ); str != "" {
3131 fmt .Println (str )
32- fmt .Printf ("Seconds passed %d\n " , second )
32+ fmt .Printf ("Part 2 | Seconds passed %d\n " , second )
3333 }
3434 }
3535}
3636
3737func dispersion (positions [][2 ]int ) string {
38- // get bounds
3938 left := math .MaxInt16
4039 right := - math .MaxInt16
4140 top := math .MaxInt16
4241 bottom := - math .MaxInt16
4342
4443 coords := map [[2 ]int ]bool {}
44+ // Get max coords from each direction.
4545 for _ , p := range positions {
4646 coords [p ] = true
4747 if p [0 ] < top {
@@ -56,16 +56,19 @@ func dispersion(positions [][2]int) string {
5656 if p [1 ] > right {
5757 right = p [1 ]
5858 }
59+ // If the distance between the top and bttom is too big, it most likely is not a
60+ // grid with letters. This value was trial and error.
5961 if bottom - top > 65 {
6062 return ""
6163 }
6264 }
6365
66+ // Assemble the coords into the letters
6467 str := ""
65- for row := top ; row <= bottom ; row ++ {
66- for col := left ; col <= right ; col ++ {
68+ for col := left ; col <= right ; col ++ {
69+ for row := top ; row <= bottom ; row ++ {
6770 if coords [[2 ]int {row , col }] {
68- str += "0 "
71+ str += "# "
6972 } else {
7073 str += " "
7174 }
0 commit comments