Quantcast
Channel: MarsHut
Viewing all articles
Browse latest Browse all 6551

Chinese remainder thereom

$
0
0
I sporadically scan the list of open tasks for J on RosettaCode:

http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_J

Most of these tasks lack a J solution for a good reason (e.g. stream
processing, low-level IO, heavy-duty GUI, multithreading, or just too many
tuits). But some fit nicely into J's domain, and simply need someone to
post a solution.

Chinese remainder thereom is an example of the latter:

http://rosettacode.org/wiki/Chinese_remainder_theorem

The algorithm looks pretty straightforward to me, and indeed I could
brute-force it by writing an explicit verb which matches, loop-for-loop,
the Python solution (for example).

But instead, I'd like to show off J's native grace and elegance;
unfortunately, it's been a long while since my undergraduate math days,
and I don't think I have the algebraic chops to tackle this problem
elegantly. Though I do have enough of a native instinct left to suspect
that there's room for a very pretty solution taking advantage of some of
J's more distinctive primitives (in particular +. #: %. seem relevant).

So, what's the most elegant way you could implement the Chinese remainder
theorem in J?

-Dan

Viewing all articles
Browse latest Browse all 6551

Trending Articles