mirror of
				https://github.com/onyx-and-iris/aoc2024.git
				synced 2025-10-30 20:41:45 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			815 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			815 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package one
 | |
| 
 | |
| import (
 | |
| 	"strings"
 | |
| )
 | |
| 
 | |
| type kindOfSchematic int
 | |
| 
 | |
| const (
 | |
| 	Lock kindOfSchematic = iota
 | |
| 	Key
 | |
| )
 | |
| 
 | |
| type schematic struct {
 | |
| 	kind    kindOfSchematic
 | |
| 	heights []int
 | |
| 	data    []string
 | |
| }
 | |
| 
 | |
| func newSchematic(buf [][]byte) *schematic {
 | |
| 	var kind kindOfSchematic
 | |
| 	data := make([]string, len(buf))
 | |
| 	heights := make([]int, len(buf[0]))
 | |
| 
 | |
| 	for i, line := range buf {
 | |
| 		data[i] = string(line)
 | |
| 
 | |
| 		if i == 0 {
 | |
| 			if allInString(data[i], '#') {
 | |
| 				kind = Lock
 | |
| 			} else if allInString(data[i], '.') {
 | |
| 				kind = Key
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		if kind == Lock && i == 0 {
 | |
| 			continue
 | |
| 		}
 | |
| 		if kind == Key && i == len(buf)-1 {
 | |
| 			continue
 | |
| 		}
 | |
| 
 | |
| 		for j, r := range data[i] {
 | |
| 			if r == '#' {
 | |
| 				heights[j]++
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return &schematic{kind, heights, data}
 | |
| }
 | |
| 
 | |
| func (s *schematic) String() string {
 | |
| 	return strings.Join(s.data, "\n")
 | |
| }
 |