day15, example

This commit is contained in:
efim 2023-12-15 14:13:36 +00:00
parent b5cb827be2
commit 192ff3878e
3 changed files with 40 additions and 3 deletions

36
day15/dayFifteen.go Normal file
View File

@ -0,0 +1,36 @@
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
}

1
day15/example Normal file
View File

@ -0,0 +1 @@
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7

View File

@ -3,12 +3,12 @@ package main
import (
"log"
"sunshine.industries/aoc2023/day14"
"sunshine.industries/aoc2023/day15"
)
func main() {
log.Print("> starting run:")
result := day14.Run()
log.Printf("day14 result: %d\n****\n", result)
result := day15.Run()
log.Printf("day15 result: %d\n****\n", result)
}