<commit_before>import FS from "fs";
import Path from "path";
import _ from "lodash-fp";

export const title = "Day 4: The Ideal Stocking Stuffer";

export function getHashWithFiveZeros(key) {
    
}

export function run() {
    const inputPath = Path.join(__dirname, "input.txt");
    const input = FS.readFileSync(inputPath, "utf-8").trim();
    
    console.log("What is find the hash which, in hexadecimal, start with at least five zeroes?", getHashWithFiveZeros(input));<commit_msg>First attempt at part one using recursion. - JavaScript doesn't have tail call optimization yet :( - Added a md5 function to make hash creation easier.<commit_after>import FS from "fs";
import Path from "path";
import Crypto from "crypto";
import _ from "lodash-fp";

export const title = "Day 4: The Ideal Stocking Stuffer";

function md5(value) {
    return Crypto
        .createHash("md5")
        .update(value)
        .digest("hex");
}

// Requires tail-end recursion. It exceeds the max call stack way too soon.
function findHashIndex(key, i) {
    const hash = md5(`${key}${i}`);

    if (hash.indexOf("00000") == 0)
        return i;

    return findHashIndex(key, i + 1);
}

export function getHashWithFiveZeros(key) {
    // return findHashIndex(key, 0);
}

export function run() {
    const inputPath = Path.join(__dirname, "input.txt");
    const input = FS.readFileSync(inputPath, "utf-8").trim();
    
    console.log("What is find the hash which, in hexadecimal, start with at least five zeroes?", getHashWithFiveZeros(input));
{'fraction_non_alphanumeric': 0.12222222222222222, 'fraction_numerical': 0.01045751633986928, 'mean_word_length': 3.8449367088607596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5787829', 'n_tokens_mistral': 495, 'n_tokens_neox': 465, 'n_words': 160}