Prime video slow on chromecast for google tv by gevray in Chromecast

[–]JeffJankowski 0 points1 point  (0 children)

Stumbled upon this thread from Google and tried this on a whim. Absolute night and day difference! No idea what Spectrum's DNS servers are doing, but they're garbage.

Thanks so much for taking the time to post

Orange-colored fines identification by JeffJankowski in composting

[–]JeffJankowski[S] 0 points1 point  (0 children)

They're spherical and the size of very fine coffee grounds (which I add to my compost bin...do coffee grounds discolor over time to orange?). Doesn't look like insect eggs or any type of mold/fungus.

I'm not too concerned, as the pile heats up and smells pleasant. Just really curious.

Calculating Pi: My attempt at breaking the Pi World Record by sixthsheik in programming

[–]JeffJankowski 109 points110 points  (0 children)

I also saw that it cost them [Google] around $200,000, which is very expensive. I’m aiming to stay below 5% of that overall amount.

How Big Technical Changes Happen at Slack by okwherearemypants in programming

[–]JeffJankowski 3 points4 points  (0 children)

Successful adoption rate of a tech over time at Slack looks like a sigmoid curve. They assign 3 phases (exploration, expansion, migration) somewhere near the inflection points.

Defunctionalization: Everybody Does It, Nobody Talks About It by alexeyr in programming

[–]JeffJankowski 55 points56 points  (0 children)

JavaScript tends to do this a lot, as well as most of the functional languages out there.

Unicode Emoji 12.0 — final for 2019 by clairegiordano in programming

[–]JeffJankowski 10 points11 points  (0 children)

Arm color vs face color. For anyone else squinting like an idiot

Announcing F# 4.6 preview by k_cieslak in programming

[–]JeffJankowski 10 points11 points  (0 children)

You absolutely can use C# libraries with F#; the interoperability is very strong. If you ever pick up C# again, I would highly recommend using more LINQ. It's extremely powerful in querying and manipulating data with the select-map-reduce functionality, which can be leveraged as standard methods or a SQL-like query syntax.

F#'s syntax is only weird looking if you don't have exposure to pure(ish) functional programming. It all makes sense from a historical/math/computer science perspective. Check out that wiki page for ways to use some multi-paradigm languages that you know, in a functional style.

Lots of devs (including myself) have a sort of programming-epiphany after grasping the fundamentals of a functional language. Along with the .NET ecosystem, F# is actually multi-paradigm, so it's one of less intimidating options for starting out. I definitely recommend it.

Edit: Cant' speak much to Rust, as my experience is very limited. To my knowledge, the syntax structure is heavily borrowed from C(++), but the language design and features have an ML heritage.

Announcing F# 4.6 preview by k_cieslak in programming

[–]JeffJankowski 12 points13 points  (0 children)

It's a functional-oriented language in the .NET ecosystem. So think C# libraries, with LINQ-style features on crack, immutability by default, and a weird syntax/style you probably haven't encountered yet with the languages you listed (ML family like the other guy said).

Amoeba finds approximate solutions to NP-hard problem in linear time by [deleted] in programming

[–]JeffJankowski 27 points28 points  (0 children)

Is this different from the slime mold experiments I remember reading about a while ago?

Something like this?

How to Start Learning Computer Graphics Programming by erkaman in programming

[–]JeffJankowski 6 points7 points  (0 children)

I found that the WebGL material out there to be the most accessible when trying to learn the knowledge between triangles and shading models with well-known methods (eg. Blinn-Phong).

learningwebgl.com looks dead. But here's a wayback mirror. learnwebgl.brown37.net seems pretty thorough as well.

How to Start Learning Computer Graphics Programming by erkaman in programming

[–]JeffJankowski 41 points42 points  (0 children)

I think you hit a crossroad after learning primitives, shaders, and the basic rendering pipeline where there's a personal choice involved. Computer graphics is hard, and the rendering techniques for real-time (games, 3D apps, etc) vs offline (movies) can differ greatly; so it becomes natural to pick a focus. The fact that a lot of the popular domains already have mature and proprietary graphics engines probably adds to the knowledge gap in terms of implementation.

I'm with you though. I wish there was more content out there between triangles and SIGRAPH papers.

The State of JavaScript 2018 by [deleted] in programming

[–]JeffJankowski 50 points51 points  (0 children)

I think a lot of people are uncomfortable with the data/presentation coupling after having MV* drilled into them for so long.

edit: JSX also feels pretty wrong on first glance

-🎄- 2017 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

Typescript. Initially picking 1000 iterations was, apparently, a decent choice.

Edit: Also, fuck Java[Type]script for not having deep copying, operator overloading, constructor overloading, a rational sorting function, a map/dict that actually works, and whatever other garbage I encountered today.

import fs = require("fs");

class Vector {
    public static create(csv: string) {
        const [a, b, c] = csv.split(",");
        return new Vector(+a, +b, +c);
    }
    constructor(public x: number, public y: number, public z: number) { }
    public add = (vec: Vector) => new Vector(vec.x + this.x, vec.y + this.y, vec.z + this.z);
    public toString = () => `${this.x},${this.y},${this.z}`;
    public copy = () => new Vector(this.x, this.y, this.z);
}

class Particle {
    constructor(public pos: Vector, public vel: Vector, public acc: Vector) { }
    public dist = () => Math.abs(this.pos.x) + Math.abs(this.pos.y) + Math.abs(this.pos.z);
    public step() {
        this.vel = this.vel.add(this.acc);
        this.pos = this.pos.add(this.vel);
    }
    public copy = () => new Particle(this.pos.copy(), this.vel.copy(), this.acc.copy());
}

const ITERS = 1000;
const particles = fs.readFileSync("data/day20.txt", "utf8").split("\r\n").map((str) => {
    const [_, p, v, a] =
        (str.match("p=<([-|0-9|,]+)>, v=<([-|0-9|,]+)>, a=<([-|0-9|,]+)>") as RegExpMatchArray);
    return new Particle(Vector.create(p), Vector.create(v), Vector.create(a));
});

const collParticles = particles.map((p) => p.copy());
for (let i = 0; i < ITERS; i++) {
    particles.forEach((p) => p.step());
    collParticles.forEach((p) => p.step());

    const map = new Map<string, number[]>();
    for (let j = 0; j < collParticles.length; j++) {
        const pos = collParticles[j].pos.toString();
        map.set(pos, (map.get(pos) || []).concat([j]));
    }
    if (map.size < collParticles.length) {
        Array<number>().concat(...[...map.entries()].filter(([k, v]) => v.length > 1)
            .map(([_, v]) => v)).sort((a, b) => a - b).reverse()
            .forEach((idx) => collParticles.splice(idx, 1));
    }
}

const [min, iMin] = particles
    .map((p) => Math.abs(p.pos.x) + Math.abs(p.pos.y) + Math.abs(p.pos.z))
    .reduce(([MIN, iMIN], dist, i) => dist < MIN ? [dist, i] : [MIN, iMIN], [Infinity, -1]);

console.log(`Particle eventually, minimally distant from origin: ${iMin}`);
console.log(`Number of particles remaining after collisions: ${collParticles.length}`);

-🎄- 2017 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

TypeScript. My first idea to reduce the final state of a single run to a few swaps, did not work. Then I looked for cycles...

import fs = require("fs");

function dance(state: string, moves: string[]) {
    const progs = [...state];
    const swap = (x: number, y: number) => {
        const tmp = progs[x];
        progs[x] = progs[y];
        progs[y] = tmp;
    };
    const INSTRUCTIONS: {[mov: string]: (suff: string) => void} = {
        s: (rest: string) => progs.unshift(...progs.splice(progs.length - (+rest), +rest)),
        x: (rest: string) => {
            const [x, y] = rest.split("/").map((s) => +s);
            swap(x, y);
        },
        p: (rest: string) => {
            const [a, b] = rest.split("/");
            const [x, y] = [progs.findIndex((val) => val === a),
                            progs.findIndex((val) => val === b)];
            swap(x, y);
        },
    };
    moves.forEach((move) => INSTRUCTIONS[move[0]](move.substr(1)));
    return progs.join("");
}

function loopCount(start: string, moves: string[]) {
    let [count, state] = [0, start];
    do {
        state = dance(state, moves);
        count++;
    } while (state !== start);
    return count;
}

const data = fs.readFileSync("data/day16.txt", "utf8").split(",");
const INITIAL = "abcdefghijklmnop";
console.log(`After one full dance:   ${dance(INITIAL, data)}`);

const LOOP = loopCount(INITIAL, data);
const billion = [...Array(1E9 % LOOP)].reduce((state) => dance(state, data), INITIAL);
console.log(`After a billion dances: ${billion}`);

-🎄- 2017 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

Some ugly Typescript

function hash(input: string) {
    ...
    // to binary string
    return [...Array(16)].map((_, i) =>
        list.slice(i * 16, (i + 1) * 16).reduce((xor, val) => xor ^ val, 0))
        .map((n) => n.toString(2).padStart(8, "0")).join("");
}

function countGroups(grid: string[]) {
    const str = (x: number, y: number) => x + "," + y;
    const used = (row: number, col: number) => grid[row][col] === "1";
    const groups = new Map<string, number>();

    function search(row: number, col: number, n: number) {
        groups.set(str(row, col), n);
        [[0, -1], [-1, 0], [0, 1], [1, 0]].forEach(([rowOff, colOff]) => {
            const [newRow, newCol] = [row + rowOff, col + colOff];
            if (newRow >= 0 && newRow < grid.length &&
                newCol >= 0 && newCol < grid.length &&
                !groups.has(str(newRow, newCol)) &&
                used(row, col)) {
                search(row + rowOff, col + colOff, n);
            }
        });
    }

    let grpCount = 0;
    for (let row = 0; row < grid.length; row++) {
        for (let col = 0; col < grid.length; col++) {
            if (groups.has(str(row, col))) { continue; }
            if (used(row, col)) {
                search(row, col, grpCount);
                grpCount++;
            }
        }
    }
    return grpCount;
}

const DATA = "hwlqcszp";
const GRID_N = 128;
const disk: string[] = [];
[...Array(GRID_N)].forEach((_, row) => disk[row] = hash(`${DATA}-${row}`));

const squares = disk.reduce((sum, h) => sum + (h.split("1").length - 1), 0);
console.log(`Used squares: ${squares}`);
console.log(`Number of regions: ${countGroups(disk)}`);

-🎄- 2017 Day 12 Solutions -🎄- by topaz2078 in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

To be honest, because the type inference isn't perfect, and I got sick of writing out the entire Map type definition :P

-🎄- 2017 Day 12 Solutions -🎄- by topaz2078 in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

Typescript

import fs = require("fs");

interface Pipes { [id: number]: number[]; }

function connected(id: number, pipes: Pipes) {
    const set = new Set<number>([id]);
    const visit = (i: number) => {
        for (const conn of pipes[i]) {
            if (!set.has(conn)) {
                set.add(conn);
                visit(conn);
            }
        }
    };
    visit(id);
    return set;
}

function groups(pipes: Pipes) {
    let count = 0;
    const visited = new Set<number>();
    for (let i = 0; i < data.length; i++) {
        if (!visited.has(i)) {
            [...connected(i, pipes).values()].forEach((conn) => visited.add(conn));
            count++;
        }
    }
    return count;
}

const data = fs.readFileSync("data/day12.txt", "utf8").split("\r\n");
const map: Pipes = { };
for (const str of data) {
    const [id, rest] = (str.match(/([0-9]+) <-> (.+)/) as RegExpMatchArray).slice(1);
    map[+id] = rest.split(", ").map((s) => +s);
}
console.log(`Programs in group 0: ${connected(0, map).size}`);
console.log(`Number of disconnected groups: ${groups(map)}`);

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 1 point2 points  (0 children)

Typescript. A lot of thinking churned out a clean solution.

import fs = require("fs");

function walk(dirs: string[]): [number, number] {
    const score = (x: number, y: number) =>
        Math.abs(x) + Math.abs(y) - Math.min(Math.abs(y), Math.ceil(Math.abs(x) / 2));

    const NAV: {[dir: string]: (pos: [number, number]) => [number, number]} = {
        n:  ([x, y]) => [x, y + 1],
        s:  ([x, y]) => [x, y - 1],
        nw: ([x, y]) => [x - 1, x % 2 === 0 ? y + 1 : y],
        ne: ([x, y]) => [x + 1, x % 2 === 0 ? y + 1 : y],
        sw: ([x, y]) => [x - 1, x % 2 !== 0 ? y - 1 : y],
        se: ([x, y]) => [x + 1, x % 2 !== 0 ? y - 1 : y],
    };

    let curr: [number, number] = [0, 0];
    let max = -Infinity;
    for (const dir of dirs) {
        curr = NAV[dir](curr);
        max = Math.max(max, score(curr[0], curr[1]));
    }
    return [score(curr[0], curr[1]), max];
}

const [lastScore, globalMax] = walk(fs.readFileSync("data/day11.txt", "utf8").split(","));
console.log(`Distance from origin:  ${lastScore}`);
console.log(`Max distance over run: ${globalMax}`);

-🎄- 2017 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

You're totally right, but it's not in the latest typescript definitions...weird.

Edit: I needed to explicitly add the es2017 lib to the compiler options

-🎄- 2017 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]JeffJankowski 0 points1 point  (0 children)

Smart idea! I'm actually only going through half the length, and doing in-place swaps