-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (36 loc) · 826 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
)
func main() {
// File reading
inputFile, err := os.ReadFile(os.Args[1])
if err != nil {
log.Fatal(err)
}
// Spliting file into lines
lines := strings.Split(string(inputFile), "\n")
var numbers []int // This variable holds the numbers
// Transforming the []byte into a []int
for _, line := range lines {
line = strings.TrimSpace(line)
if line == "" {
continue
}
num, err := strconv.Atoi(line)
if err != nil {
log.Printf("Skipping line %q: %v\n", line, err)
continue
}
numbers = append(numbers, num)
}
// Printing the results
fmt.Println("Average:", Average(numbers))
fmt.Println("Median:", Median(numbers))
fmt.Println("Variance:", Variance(numbers))
fmt.Println("Standard Deviation:", StandardDeviation(numbers))
}