Browse Source

Solved for sample

Piotr Czajkowski 1 year ago
parent
commit
ac255c2fa4
1 changed files with 20 additions and 1 deletions
  1. 20 1
      15/code.go

+ 20 - 1
15/code.go

@@ -25,11 +25,30 @@ func readInput(path string) []string {
 	return parts
 }
 
+func hash(text string) int {
+	var current int
+	for i := range text {
+		current += int(text[i])
+		current = current * 17 % 256
+	}
+
+	return current
+}
+
+func part1(steps []string) int {
+	var result int
+	for i := range steps {
+		result += hash(steps[i])
+	}
+
+	return result
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
 	}
 
 	steps := readInput(os.Args[1])
-	fmt.Println(steps)
+	fmt.Println("Part1:", part1(steps))
 }