On Wed, Aug 28, 2019 at 11:23 AM Skip Cave <s...@caveconsulting.com> wrote:
> Looks like Pete had issues with the efficiency of his J solution to the
> Advent of Code: Marble Mania problem:
> http://www.petecorey.com/blog/2018/12/14/advent-of-code-marble-mania/

That problem needs to work with three independent values:

1) The "board" of placed marbles
2) The number of the next marble to be placed
3) The scores of each of the elves (which implies knowing how many
elves are playing)

For something like this, I'd be strongly tempted to use OOP:
https://www.jsoftware.com/help/learning/25.htm for the first draft. It
might be possible to simplify things analytically, but I'd like to
have working examples in front of me, to test against, before I went
there.

Simplifications:

(1) creating an instance of the initial version of the game only needs
to know how many are playing (and, in a sense, how long the game will
continue - though using that number implies playing that game to
completion).

(2) We can represent the "current marble" by rotating the board so
it's at position 0. [There may be faster approaches, but I'd want to
be able to compare the speed of the possibly faster approach to this
approach to know if it's actually faster. Approaches taking advantage
of mathematical equivalences be faster.]

I'd actually start out by coding for the case where the board has 3 or
4 marbles on it. Then I'd start dealing with the other possibilities.

This is close to how he approached it, so it's likely to run into some
of the same speed issues.

Note that it's also possible to use an approach based on using modulo
arithmetic on indices and #!.n inv (or complex #!.n ) but by itself
that won't be faster. To be faster, I think I might try working out
how to do "batches of 23" as "one step". I suspect that would get me
something close to a 10x speedup.

But, anyways, my experience with those "advent of code" problems has
been that they are designed to tend to take hours to solve, and often
reqire several code versions.

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to