Skip to content

Instantly share code, notes, and snippets.

@glitchcowboy
Created January 3, 2024 15:32
Show Gist options
  • Save glitchcowboy/b227c6f03ccc8bb82295d787ed7ac950 to your computer and use it in GitHub Desktop.
Save glitchcowboy/b227c6f03ccc8bb82295d787ed7ac950 to your computer and use it in GitHub Desktop.
AoC-Day1-broken.go
package main
import (
"encoding/csv"
"os"
//"strings"
"regexp"
"fmt"
//"strings"
//"strconv"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
file, err := os.Open("input.txt")
check(err)
defer file.Close()
reader := csv.NewReader(file)
records, err := reader.ReadAll()
check(err)
connector_re := regexp.MustCompile(`[^\.\d]+`)
num_re := regexp.MustCompile(`\d+`)
for i:=0; i<len(records); i++{
record := records[i]
//var r_connectors [][]int
var r_numbers [][]int
//r_connectors = connector_re.FindAllStringSubmatchIndex(record[0],-1)
r_numbers = num_re.FindAllStringSubmatchIndex(record[0],-1)
for _, num := range r_numbers{
fmt.Println("record:",i,num)
//Check for non-numbers in next line adjacent to current number
nextLinePrevChar := []byte(records[1][num[0]-1])
fmt.Println("nextline previous char", nextLinePrevChar)
if connector_re.Match(nextLinePrevChar) {
fmt.Println("nextline previous char", nextLinePrevChar)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment