Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Xarn
Jun 26, 2015

After I finally gave in and used regexes for a problem, the second part kinda hurt.

So I just created a bracket matcher and deleter. Sometimes everything IS a nail. :v:

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015
Why is the site down just as I decided to procrastinate and code? :v:

Also 9 (and 14, duh) is the one that I haven't done yet. Its not hard per se, it will just take some annoying boilerplate I don't care for writing, especially since I want to do it properly. (Construct an ad-hoc graph and then solve it by going from the leaves.)

Xarn
Jun 26, 2015

Volguus posted:

I loving hate Day 12 (was away for a week, catching up now). Phase 1 was able to do without a json parser and no regex's (yet, knock on wood). And it was really simple and clever. And in phase 2 now it makes me either make a json parser, use one or implement some mind-twisting, soul-hating state machine that I'll remember forever in the "what not to do" section of programming experiences.

I guess I'll just have to get in line and use this son of jay ....

I said it once already, but I just used an ad-hoc brace matcher...

C++ code:
size_t find_start(const std::string& str, size_t pos) {
    int square_level = 1;
    int brace_level = 1;
    while (--pos) {
        switch (str[pos]) {
        case ']':
            square_level++;
            break;
        case '[':
            square_level--;
            if (square_level == 0) {
                return pos;
            }
            break;
        case '}':
            brace_level++;
            break;
        case '{':
            brace_level--;
            if (brace_level == 0) {
                return pos;
            }
            break;
        default:
            break;
        }
    }
    assert(false && "unmatched parens");
}
Yes, I did run it in Release mode so the assert did nothing anyway, why do you ask? :v:

Xarn
Jun 26, 2015

Volguus posted:

Yes, and then inbetween you had to find the offending string, then find_start again. I chose to keep a bit of my sanity and just use a drat parser.

Eh, the rest of the solution was just using string::find in a loop and a bit more logic to find the ending "}" if applicable.

As for day 17, I'd love if the inputs started veering away from brute force. There is a proper and easy algorithm for this, but if I was doing these in Python I'd just brute force it because its easy and the input is insanely small.

Xarn
Jun 26, 2015

I haven't done it yet, but please tell me that part 2 is Game of Life on a toroidal board. :v:

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

chutwig posted:

Finally had time to return to the problems after a busy December and restart all the way back at problem 7. Having it laid bare that I'm a systems programmer with little knowledge of algorithms is teeth-gritting sometimes, but that makes it all the more gratifying when I get the solution.

You are in luck then, most of the problems are either intended to be solved by brute force, or solvable by using brute force because of small problem size. :v:

  • Locked thread