Advent-of-Code-2023/day15/dayFifteen.go

37 lines
607 B
Go

package day15
import (
"fmt"
"os"
"strings"
)
func Run() int {
fmt.Println("hello day 15")
filename := "day15/example"
bytes, err := os.ReadFile(filename)
if err != nil {
panic(fmt.Sprint("error reading file ", filename))
}
text := string(bytes)
text = strings.TrimSpace(text)
instructions := strings.Split(text, ",")
result := 0
for _, instruction := range instructions {
result += ASCIIStringHash(instruction)
}
return result
}
func ASCIIStringHash(str string) int {
result := 0
for _, symb := range str {
result += int(symb)
result *= 17
result %= 256
}
return result
}