Skip to content

Commit

Permalink
AoC 2024 day 22 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed Dec 28, 2024
1 parent dfad983 commit bda6551
Show file tree
Hide file tree
Showing 8 changed files with 2,317 additions and 0 deletions.
Empty file added aoc2024/src/day22/__init__.py
Empty file.
Empty file.
35 changes: 35 additions & 0 deletions aoc2024/src/day22/python/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Sequence


def _mix(secret_number: int, value: int) -> int:
return secret_number ^ value


def _prune(secret_number: int) -> int:
return secret_number % 16777216


def generate_secret_number(secret_number: int, times: int = 1) -> int:
result = secret_number
for _ in range(times):
result = _prune(_mix(result, result * 64))
result = _prune(_mix(result, result // 32))
result = _prune(_mix(result, result * 2048))
return result


def sum_2000th_secret_numbers(secret_numbers: Sequence[str]) -> int:
return sum(generate_secret_number(secret_number=int(secret_number), times=2000) for secret_number in secret_numbers)
Empty file added aoc2024/test/day22/__init__.py
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions aoc2024/test/day22/python/example1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
10
100
2024
Loading

0 comments on commit bda6551

Please sign in to comment.