initialise

This commit is contained in:
Javier-Orestis MANTZIOS
2025-01-07 10:39:37 +02:00
commit 108f50e8ea
25 changed files with 5534 additions and 0 deletions

50
2/main.go.BAK Normal file
View 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
}
}
}