advent-of-code

Entries to advent of code, multiple years
git clone git://git.finwo.net/misc/advent-of-code
Log | Files | Refs

commit 32356ba5b19ce392bb6c5884b3793279b7525b68
parent 7a4b8b331576881e4e16e21ba140f5894590bc89
Author: finwo <finwo@pm.me>
Date:   Tue, 15 Nov 2022 16:51:58 +0100

Added 2015/04 solution

Diffstat:
A2015/day-04/index.js | 11+++++++++++
M2015/package-lock.json | 30++++++++++++++++++++++++++++++
M2015/package.json | 1+
3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/2015/day-04/index.js b/2015/day-04/index.js @@ -0,0 +1,11 @@ +const fs = require('fs'); +const { hex_md5 } = require('@finwo/digest-md5'); + +const secret = fs.readFileSync('input', 'utf-8').trim(); +const difficulty = 6; +const matcher = '0'.repeat(difficulty); +let nonce = 0; + +while(hex_md5(secret + nonce).substr(0,difficulty) != matcher) nonce++; + +console.log({ secret, hash: hex_md5(secret + nonce), nonce }); diff --git a/2015/package-lock.json b/2015/package-lock.json @@ -9,9 +9,26 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@finwo/digest-md5": "^1.0.2", "through2": "^4.0.2" } }, + "node_modules/@finwo/digest-common": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@finwo/digest-common/-/digest-common-1.1.0.tgz", + "integrity": "sha512-8O+Py3CsilUHT6IetstrFJnTcGDaQpfWfh3o+idEFLrsJRrx/G5eI9rY1uMVa32EteQeRW/kBg8KIn5zu7HMHg==" + }, + "node_modules/@finwo/digest-md5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@finwo/digest-md5/-/digest-md5-1.0.2.tgz", + "integrity": "sha512-Z3JfmDSB+lBsjIyq7HzATLsUoGnuc39V2sLiVQKbi4ef0fBwqo1BjE9zmjCW8rqXTkraTNi6qZVsfgV0mYQGGA==", + "dependencies": { + "@finwo/digest-common": "^1.1.0" + }, + "funding": { + "url": "https://github.com/sponsors/finwo" + } + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -72,6 +89,19 @@ } }, "dependencies": { + "@finwo/digest-common": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@finwo/digest-common/-/digest-common-1.1.0.tgz", + "integrity": "sha512-8O+Py3CsilUHT6IetstrFJnTcGDaQpfWfh3o+idEFLrsJRrx/G5eI9rY1uMVa32EteQeRW/kBg8KIn5zu7HMHg==" + }, + "@finwo/digest-md5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@finwo/digest-md5/-/digest-md5-1.0.2.tgz", + "integrity": "sha512-Z3JfmDSB+lBsjIyq7HzATLsUoGnuc39V2sLiVQKbi4ef0fBwqo1BjE9zmjCW8rqXTkraTNi6qZVsfgV0mYQGGA==", + "requires": { + "@finwo/digest-common": "^1.1.0" + } + }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", diff --git a/2015/package.json b/2015/package.json @@ -9,6 +9,7 @@ "author": "", "license": "ISC", "dependencies": { + "@finwo/digest-md5": "^1.0.2", "through2": "^4.0.2" } }