Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The goal of this particular implementation was to be highly algorithmically efficient, so no hidden computational costs of regex which could otherwise lead to quadratic, or worse time complexity. That's why everything is "coded by hand".
The
decodeBits()
method is linear time, and generally a fast linear time due to an early return optimization in thefindTransmissionRate()
method which can return early as long as the "bit rate" is not 3 or 7, (both of which are valid "character" lengths). The runtime of thebitstreamToMorse()
method isbits.length() / rate
where rate is the "bit rate" of the string so may be extra fast as long asrate > 1
.The
decodeMorse()
method also runs in linear time.Last line should be
return openingBraces.isEmpty();
Another accidental submission. I absolutely hate how when you make some change to the code while refactoring after a successful attempt but hit ctrl-z to remove the change in the editor it changes the "Attempt" button back to the "Submit" button.
i = -1;
should probably bei = (i > 1) ? i - 2 : -1;
(or some such) as an optimization.This part:
Could have been written:
But I, personally, think the first version is easier to understand at a glance.
Should have read the
BigInteger
documentation more thoroughly to discover theBigInteger.nextProbablePrime()
method. The program was originallylong primorial = 1
rather thanBigInteger primorial = BigInteger.ONE;
hence the original need to generate the primes manually. With that in mind, thenumPrimorial()
method would look like this:And that would be the entire program.
Factored out
getDecompString(factors)
and now each function has a very clearly-delineated purpose. The performance is IMO rather good, 600-700 ms on the main test. I can't really think of any way of speeding it up without sacrificing too much from the readability which would be counter to my personal purposes which is to make cleaner, more maintainable code, hence the use of short, clearly-defined functions.Obsolete version. I forgot to cast loop condition variable to
(int)
double sequenceLength = Math.sqrt(max);
should be
int sequenceLength = (int)Math.sqrt(max);
This was an accidental submission before refactoring, hence the superfluous
if (snail.size() == totalSize) { break start; }
statements...I keep accidentally submitting things when I mean to refactor them first and there's apparently no way to delete old versions... Anyway, this version is obsolete.
This comment is hidden because it contains spoiler information about the solution
I wanted to see if I could make myself barf coming up with this disaster.