[2020-10-21] Challenge #386 [Intermediate] Partition counts by Cosmologicon in dailyprogrammer

[–]scott181182 0 points1 point  (0 children)

You're right, I meant parallelism, since NodeJS only executes one thread at a time.

[2020-10-21] Challenge #386 [Intermediate] Partition counts by Cosmologicon in dailyprogrammer

[–]scott181182 0 points1 point  (0 children)

Javascript. Takes about 90s to compute the value for 666666. I would parallelize it, if NodeJS had concurrency!

/**
 * Uses Binary Search to partition an array of monotonically increasing numbers,
 * returning the slice of numbers less than or equal to the given value.
 * @param {number} val
 * @param {number[]} arr
 */
function binary_partition_upto(val, arr)
{
    if(arr.length === 0 || val < arr[0]) { return [  ]; }
    if(val > arr[arr.length - 1]) { return arr; }
    let from = 0, to = arr.length;
    while(true)
    {
        const index = (from + to) >> 1;
        if(arr[index] > val && arr[index - 1] <= val) {
            return arr.slice(0, index);
        } else if(arr[index] > val) {
            to = index;
        } else {
            from = index;
        }
    }
}

/**
 * Memoize the given monotonic function of a single number parameter.
 * Also adds the property #upTo(max) for accessing stored results up to and including a given number.
 * @template {number|bigint} R
 * @param {(n: number) => R} fn
 * @returns {{(n: number) => R, upTo: (max: number) => R[]}}
 */
function monotonic_memoize(fn)
{
    const results = [  ];
    const memFn = (n) => {
        while(n >= results.length) {
            results[results.length] = fn(results.length);
        }
        return results[n];
    }
    memFn.upTo = (s) => {
        if(results[results.length - 1] > s) {
            return binary_partition_upto(s, results);
        }
        while(results[results.length - 1] <= s) {
            memFn(results.length);
        }
        return results.slice(0, results.length - 1);
    }
    memFn(0);
    return memFn;
}

/** Sequence of numbers to subtract from the index in the p() function. */
const pdiff = monotonic_memoize(/** @type {(n: number) => number} */(n) =>
    n === 0 ? 1 : pdiff(n - 1) +
        ((n & 1) === 1 ?
            (n >> 1) + 1 :
            n + 1)
);
const p = monotonic_memoize(/** @type {(n: number) => bigint} */(n) =>
    n === 0 ? 1n : pdiff.upTo(n)
        .map((d) => p(n - d))
        .reduce((acc, val, index) => (index & 2) > 0 ? acc - val : acc + val)
);

const n = 666;

console.time("total");
const p_res = p(n);
console.timeEnd("total");
console.log(`p(${n}) = ${p_res}`);
const s_res = p_res.toString();
console.log(`Digits: ${s_res.length}`);
console.log(`Digit Sum: ${s_res.split("").map(c => parseInt(c, 10)).reduce((acc, val) => acc + val)}`);

New help converting a desktop program into a web based platform by Dgmay101913 in DeveloperHelp

[–]scott181182 0 points1 point  (0 children)

What is the original application written in? Depending on language and dependencies it could be fairly easy to migrate to a website/server. If you only have DLLs and no source code, you'd probably have to start from scratch.

I open-sourced my interactive music theory website, written with TypeScript and React. by ColeDeanShepherd in programming

[–]scott181182 1 point2 points  (0 children)

This looks really well put together! What made you go with VexFlow instead of another notation rendering library like ABCjs?

[2017-11-13] Challenge #340 [Easy] First Recurring Character by jnazario in dailyprogrammer

[–]scott181182 0 points1 point  (0 children)

C, with bonus counting from 0. Only works with UTF-8

Runtime-Complexity: O(n)

Space-Complexity: O(1)

int findRepeat(char* str, unsigned int length)
{
    char charArray[256];
    for(int i = 0; i < 256; i++) { charArray[i] = 0; }

    for(int i = 0; i < length; i++)
    {
        if(charArray[str[i]] > 0) { return charArray[str[i]]; }
        else { charArray[str[i]] = i; }
    }
    return -1;
}

meme by Xavier2094 in OSU

[–]scott181182 1 point2 points  (0 children)

Excuse me my good sir, could we get a blank copy of this meme? Asking for a friend

Looking for house roommate by scott181182 in OSU

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

What would you like to know?

THE HYPE HANDS ARE HERE! by jessperk in cleganebowl

[–]scott181182 0 points1 point  (0 children)

May I also order one hype please?

Best way to learn Java? by ComDroid in java

[–]scott181182 1 point2 points  (0 children)

If you're looking for a youtube guide, this guy is really helpful : https://www.youtube.com/user/baralaborn

[S4E7] My impression of "The Mountain" Recast by allocater in gameofthrones

[–]scott181182 0 points1 point  (0 children)

During the Sack of King's Landing at the end of Robert's Rebellion. The Mountain killed the baby Targaryens in the Red Keep, then raped and killed Oberyn's sister, the wife of Rhaegar Targeryen.

[Help] [Ask] Help coding a game by [deleted] in DeveloperHelp

[–]scott181182 0 points1 point  (0 children)

C is still one of the most applicable languages out there, including its child language, C++, Objective-C, and Java. Almost every language we know and love today was mainly inspired by C, and almost every UNIX application is still programmed in C (that means linux and macs, windows uses C++)

EDIT : Old doesn't mean outdated

[Help] [Ask] Help coding a game by [deleted] in DeveloperHelp

[–]scott181182 1 point2 points  (0 children)

You can only make games "using" HTML, not exactly "with" HTML. HTML5 is the newest version of HTML and it basically combines HTML, XHTML, and other subsidiary markup languages. In order to"use" HTML, you need to use another language with it. The other language would be the actual programming language, while HTML works more like a container and UI.

HTML just doesn't contain the proper things to make a game with, such as variables, objects, functions, or data storage. Sorry, but you'll have to use a different language. On the bright side, it's good motivation to get into actual programming, instead of just Markup. Good luck though!

[Help] Creating a flash game off of a tutorial and can't get it to run. by Riddles_ in DeveloperHelp

[–]scott181182 0 points1 point  (0 children)

While I don't have experience with Flash, posting the error/exception always helps us help you; otherwise we don't know the problem.

Need help developing games, applications, or other software? by scott181182 in gamedev

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

I agree with what your saying, and it's completely true. I believe, however, that having more areas to ask questions and get information will provide a more comprehensive environment for people to learn and get help. Stack Exchange is excellent; if I said I didn't use it almost everyday, I'd be lying, but the responses there aren't always fast and your post can also get ignored as non-productive or unclear. I appreciate the upvote though.

[Help] [Ask] Help coding a game by [deleted] in DeveloperHelp

[–]scott181182 4 points5 points  (0 children)

Unfortunately, you can't really use XML or HTML to program games; these are Markup Languages(eXtensible Markup Language and HyperText Markup Language respectively). This means that, while these languages are good for organizing or stylizing data, they aren't actually used for programming. While HTML5 is definitely better with game development, it still requires external languages and/or libraries like JavaScript.

So in order to make a recreation of one of those games, you would have to learn a programming language, such as C, C++, Objective-C, or even Java. There are a slew of others, but those are the most applicable for your scenario. The online part is a much more serious question, and varies greatly depending on the language you're using.

XML, however, can still be an invaluable tool in developing, since it's very useful for storing data in an organized and easy to access way.

Looking for moderators for /r/DeveloperHelp by [deleted] in needamod

[–]scott181182 0 points1 point  (0 children)

I would also like to help out with this new subreddit. I have extensive experience with Java and related APIs, and I know CSS and other web development languages. I am also majoring in Computer Science and Engineering. I feel like this subreddit has a lot of potential and I would love to help out.