Skip to content

Commit bb70c2a

Browse files
committed
day1 part2 by llm
1 parent 71bbf52 commit bb70c2a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/adventofcode2024/day01.odin

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ main :: proc() {
2626

2727
part2_result := part2(x[:], y[:])
2828
fmt.println(part2_result) // 20520794
29+
30+
fmt.println(calculate_similarity_score(x[:], y[:])) // 20520794
2931
}
3032

3133
part1 :: proc(x, y: []int) -> int {
@@ -62,3 +64,26 @@ part2 :: proc(x, y: []int) -> int {
6264

6365
return result
6466
}
67+
68+
// solution by LLM part 2
69+
70+
// Calculate similarity score
71+
calculate_similarity_score :: proc(left_list, right_list: []int) -> int {
72+
// Count frequencies of numbers in the right list
73+
frequencies := make(map[int]int)
74+
defer delete(frequencies)
75+
76+
for num in right_list {
77+
frequencies[num] += 1
78+
}
79+
80+
// Calculate similarity score
81+
total_score := 0
82+
for num in left_list {
83+
// Multiply number by its frequency (0 if not found)
84+
frequency := frequencies[num] or_else 0
85+
total_score += num * frequency
86+
}
87+
88+
return total_score
89+
}

0 commit comments

Comments
 (0)