mirror of
				https://github.com/onyx-and-iris/aoc2024.git
				synced 2025-10-31 04:51:46 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			634 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			634 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package two
 | |
| 
 | |
| import (
 | |
| 	"bufio"
 | |
| 	"io"
 | |
| 	"regexp"
 | |
| 
 | |
| 	log "github.com/sirupsen/logrus"
 | |
| )
 | |
| 
 | |
| var reStartPos = regexp.MustCompile(`0`)
 | |
| 
 | |
| func parseLines(r io.Reader) (*graph, error) {
 | |
| 	graph := newGrid()
 | |
| 
 | |
| 	var linecount int
 | |
| 	scanner := bufio.NewScanner(r)
 | |
| 	for scanner.Scan() {
 | |
| 		line := scanner.Text()
 | |
| 
 | |
| 		graph.data = append(graph.data, line)
 | |
| 		for _, m := range reStartPos.FindAllStringIndex(line, -1) {
 | |
| 			graph.startPositions = append(
 | |
| 				graph.startPositions,
 | |
| 				point{x: m[0], y: linecount},
 | |
| 			)
 | |
| 		}
 | |
| 
 | |
| 		linecount++
 | |
| 	}
 | |
| 
 | |
| 	log.Debug(graph.startPositions)
 | |
| 
 | |
| 	if err := scanner.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	return graph, nil
 | |
| }
 |