day1 and 2 done & setup for day3
This commit is contained in:
parent
5053b3cbbd
commit
be09a5df2c
26 changed files with 2520 additions and 2 deletions
|
@ -1,7 +1,58 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("hallo")
|
||||
data := LoadData("./data")
|
||||
c := CountIncreases(&data)
|
||||
fmt.Println(c)
|
||||
data = MutateDataPart2(data)
|
||||
c = CountIncreases(&data)
|
||||
fmt.Println(c)
|
||||
}
|
||||
|
||||
func MutateDataPart2(data []DataEntry) []DataEntry {
|
||||
var result []DataEntry
|
||||
lastInt := 0
|
||||
for i := range data {
|
||||
if i >= len(data)-2 {
|
||||
continue
|
||||
}
|
||||
value := data[i].Value + data[i+1].Value + data[i+2].Value
|
||||
var status Status
|
||||
switch {
|
||||
case lastInt == 0:
|
||||
status = Nothing
|
||||
case lastInt < value:
|
||||
status = Increased
|
||||
case lastInt > value:
|
||||
status = Decreased
|
||||
case lastInt == value:
|
||||
status = Equal
|
||||
}
|
||||
lastInt = value
|
||||
result = append(result, DataEntry{
|
||||
Value: value,
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func CountIncreases(d *[]DataEntry) int {
|
||||
var count int
|
||||
for _, d := range *d {
|
||||
if d.Status == Increased {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue