-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): add solutions for 2024 day 22 part 1
- Loading branch information
1 parent
6f895c3
commit d7ed943
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
part-one: | ||
- input: | | ||
1 | ||
10 | ||
100 | ||
2024 | ||
answer: 37327623 |