File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ 5,4
2+ 4,2
3+ 4,5
4+ 3,0
5+ 2,1
6+ 6,3
7+ 2,4
8+ 1,5
9+ 0,6
10+ 3,3
11+ 2,6
12+ 5,1
13+ 1,2
14+ 5,5
15+ 2,5
16+ 6,5
17+ 1,4
18+ 0,4
19+ 6,4
20+ 1,1
21+ 6,1
22+ 1,0
23+ 0,5
24+ 1,6
25+ 2,0
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "flag"
6+ "fmt"
7+ "os"
8+ "regexp"
9+
10+ "github.com/fxnn/adventofcode2024/util"
11+ )
12+
13+ const (
14+ CORRUPTED = - 1
15+ )
16+
17+ func printSpace (space [][]int ) {
18+ for y := range space {
19+ for x := range space [y ] {
20+ fmt .Printf ("%2d " , space [y ][x ])
21+ }
22+ fmt .Println ()
23+ }
24+ fmt .Println ()
25+ }
26+
27+ func main () {
28+ var size = flag .Int ("max" , 70 , "coordinates have range [0,max]" )
29+ var count = flag .Int ("count" , 1024 , "number of bytes that have fallen" )
30+ flag .Parse ()
31+ var space = make ([][]int , * size + 1 )
32+ for y := range space {
33+ space [y ] = make ([]int , * size + 1 )
34+ }
35+
36+ var scanner = bufio .NewScanner (os .Stdin )
37+ var pattern = regexp .MustCompile (`^(\d+),(\d+)$` )
38+
39+ var fallen int
40+ for scanner .Scan () && fallen < * count {
41+ var line = scanner .Text ()
42+ var matches = pattern .FindStringSubmatch (line )
43+ var x , y int
44+ if len (matches ) > 0 {
45+ x = util .Atoi (matches [1 ])
46+ y = util .Atoi (matches [2 ])
47+ space [y ][x ] = CORRUPTED
48+ fallen ++
49+ }
50+ }
51+ if err := scanner .Err (); err != nil {
52+ fmt .Fprintf (os .Stderr , "Error: %s\n " , err )
53+ os .Exit (1 )
54+ }
55+
56+ printSpace (space )
57+ }
You can’t perform that action at this time.
0 commit comments