37 lines
605 B
Go
37 lines
605 B
Go
package day15
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func Run() int {
|
|
fmt.Println("hello day 15")
|
|
filename := "day15/input"
|
|
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
|
|
}
|