day15, example
This commit is contained in:
parent
b5cb827be2
commit
192ff3878e
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
|
6
main.go
6
main.go
|
@ -3,12 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"sunshine.industries/aoc2023/day14"
|
"sunshine.industries/aoc2023/day15"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Print("> starting run:")
|
log.Print("> starting run:")
|
||||||
|
|
||||||
result := day14.Run()
|
result := day15.Run()
|
||||||
log.Printf("day14 result: %d\n****\n", result)
|
log.Printf("day15 result: %d\n****\n", result)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue