package main import ( "bufio" "fmt" "math" "os" "slices" "strconv" "strings" ) func main() { filePath := "input" file, err := os.Open(filePath) if err != nil { fmt.Printf("Error opening file: %v\n", err) return } defer file.Close() scanner := bufio.NewScanner(file) report := [][]int{} i := 0 safeCount := 0 safe := true for scanner.Scan() { safe = true line := scanner.Text() parts := strings.Fields(line) for j := range parts { level, _ := strconv.Atoi(parts[j]) report[i] = append(report[i], level) } if slices.IsSorted(report[i]) { for j := range report[i] { if j < len(report[i]) { if 1 >= math.Abs(float64(report[i][j]-report[i][j+1])) && math.Abs(float64(report[i][j]-report[i][j+1])) > 3 { safe = false } } } } else { safe = false } if safe { safeCount = safeCount + 1 } } }