Howdy! 👋

I’m level 27 web dev from 🇫🇮 Finland. Full stack developer by trade but more into server side and sysadmin stuff.

A furry or something. Why be yourself when you can be fluffy raccoon on the internet?

I’m also on Mastodon: @jakeRaccoon@mastodon.social

  • 1 Post
  • 29 Comments
Joined 1 year ago
cake
Cake day: June 20th, 2023

help-circle

  • Cool, thanks for the explanation.

    a single application that gets bundled with all necessary dependencies including versioning

    Does that mean that if I were to install Application A and Application B that both have dependency to package C version 1.2.3 I then would have package C (and all of its possible sub dependencies) twice on my disk? I don’t know how much external dependencies applications on Linux usually have but doesn’t that have the potential to waste huge amounts of disk space?















  • TypeScript

    GitHub link

    It’s nice to have a quick easy one for a change

    Code
    import fs from "fs";
    
    const rows = fs.readFileSync("./09/input.txt", "utf-8")
        .split(/[\r\n]+/)
        .map(row => row.trim())
        .filter(Boolean)
        .map(row => row.split(/\s+/).map(number => parseInt(number)));
    
    console.info("Part 1: " + solve(structuredClone(rows)));
    console.info("Part 2: " + solve(structuredClone(rows), true));
    
    function solve(rows: number[][], part2 = false): number {
        let total = 0;
        for (const row of rows) {
            const sequences: number[][] = [row];
            while (sequences[sequences.length - 1].some(number => number !== 0)) { // Loop until all are zero
                const lastSequence = sequences[sequences.length - 1];
                const newSequence: number[] = [];
                for (let i = 0; i < lastSequence.length; i++) {
                    if (lastSequence[i + 1] !== undefined) {
                        newSequence.push(lastSequence[i + 1] - lastSequence[i]);
                    }
                }
                sequences.push(newSequence);
            }
    
            // For part two just reverse the sequences
            if (part2) {
                sequences.forEach(sequence => sequence.reverse());
            }
    
            // Add the first zero manually and loop the rest
            sequences[sequences.length - 1].push(0);
            for (let i = sequences.length - 2; i >= 0; i--) {
                sequences[i].push(part2
                    ? sequences[i][sequences[i].length - 1] - sequences[i + 1][sequences[i + 1].length - 1]
                    : sequences[i][sequences[i].length - 1] + sequences[i + 1][sequences[i + 1].length - 1]
                );
            }
        
            total += sequences[0].reverse()[0];
        }
    
        return total;
    }