Skip to content

Commit

Permalink
feat(js): add solutions for 2024 day 22 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
timkurvers committed Dec 22, 2024
1 parent 6f895c3 commit d7ed943
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
30 changes: 30 additions & 0 deletions js/src/2024/22/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { mod, solution } from '../../utils/index.js';

const parse = (input) => input.trim().split('\n').map(Number);

const prune = (value) => mod(value, 16777216);

const mix = (value, secret) => value ^ secret;

const next = (value) => {
let result = prune(mix(value * 64, value));
result = prune(mix((result / 32) | 0, result));
result = prune(mix(result * 2048, result));
return result;
};

export const partOne = solution((input) => {
const numbers = parse(input);

let sum = 0;
for (const number of numbers) {
let result = number;
for (let i = 0; i < 2000; ++i) {
result = next(result);
}
sum += result;
}
return sum;
});

// TODO: Ain't nobody got time for part two ;)
7 changes: 7 additions & 0 deletions puzzles/2024/22/examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
part-one:
- input: |
1
10
100
2024
answer: 37327623

0 comments on commit d7ed943

Please sign in to comment.