initialise
This commit is contained in:
50
2/main.go.BAK
Normal file
50
2/main.go.BAK
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user