This forum is in permanent archive mode. Our new active community can be found here.

Weekend coding

13334353638

Comments

  • Late to the party, but I've got time at work today, so I'll do some of this action. Already finished day 1.

    https://github.com/Apreche/advent2016
  • edited December 2016
    Day 5 part 2 is taking quite a long time to process.
    $ python md5bunny.py
    FOUND: abbhdwsy1910966 | 0000004ed0ede071d293b5f33de2dc2f | ['4', '', '', '', '', '', '', '']
    FOUND: abbhdwsy1997199 | 0000012be6057b2554c26bfddab18b08 | ['4', '2', '', '', '', '', '', '']
    I've been waiting quite awhile for the next character to appear with my virtual machine CPU pegged.
    Post edited by Apreche on
  • Code isn't that complicated
    password_two = ['' for x in range(8)]

    index = 0
    while '' in password_two:
    string = "%s%s" % (door_id, index)
    checksum = md5hash(string)
    if checksum[:5] == '00000':
    try:
    password_index = int(checksum[5])
    except ValueError:
    continue
    password_char = checksum[6]
    if password_index >= 0 and password_index < 8:
    if password_two[password_index] == '':
    password_two[password_index] = password_char
    print "FOUND: %s | %s | %s" % (string, checksum, password_two)
    index += 1

    print "ANSWER 2: %s" % ''.join(password_two)
  • Why don't you use if checksum[5].isdigit() and "{}{}".format(stuff, other_stuff)?
  • Starfox said:

    Why don't you use if checksum[5].isdigit() and "{}{}".format(stuff, other_stuff)?

    I think I don't use isdigit because I just don't like such explicit input validation. It feels really tedious to me for some reason. As for new style formatting, I'm just used to old style formatting.
  • Ok, seems to be working now. I think it was the change from checking for a ValueError to the isdigit. There shouldn't be any difference, though... Maybe the location of the continue statement was behaving differently than I expected.
  • Maybe a speed thing? My guess is that a function call should be faster than handling the exception, but not sure by how much.
  • def foo():
    try:
    int('asdf')
    except:
    pass

    def bar():
    'asdf'.isdigit()

    def baz():
    try:
    int('1234')
    except:
    pass

    def qux():
    '1234'.isdigit()
    >>> timeit.timeit(foo, number=10000000)
    9.470818042755127
    >>> timeit.timeit(bar, number=10000000)
    0.8520801067352295
    >>> timeit.timeit(baz, number=10000000)
    2.6653380393981934
    >>> timeit.timeit(qux, number=10000000)
    0.8670921325683594
    Nontrivial, it appears. You should raise an exception 6/16ths of the time, right? So about halfway between 9 and 2 seconds, vs ~1 for isdigit.
  • edited December 2016
    DAMN

    I'm onto day 6. It's looking easy so far.
    Post edited by Apreche on
  • All caught up to day 7. My day 7 solution though. It is not elegant.
  • Apreche said:

    Ok, seems to be working now. I think it was the change from checking for a ValueError to the isdigit. There shouldn't be any difference, though... Maybe the location of the continue statement was behaving differently than I expected.

    If the "continue" happens, index += 1 doesn't happen, so that would be an infinite loop.
  • Apreche said:

    All caught up to day 7. My day 7 solution though. It is not elegant.

    I used the power of regex!

    https://gist.github.com/lackofcheese/32c4ecf4c0680ffdd758442382e18ffc
  • Apreche said:

    Ok, seems to be working now. I think it was the change from checking for a ValueError to the isdigit. There shouldn't be any difference, though... Maybe the location of the continue statement was behaving differently than I expected.

    If the "continue" happens, index += 1 doesn't happen, so that would be an infinite loop.
    Aha!

    Apreche said:

    All caught up to day 7. My day 7 solution though. It is not elegant.

    I used the power of regex!

    https://gist.github.com/lackofcheese/32c4ecf4c0680ffdd758442382e18ffc
    I also used regex for many of the problems, but that kind of regex is one level higher than my knowledge.
  • "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."

    - Jamie Zawinski
  • And on the 8th day Lord Scott solved the problem with TWO files, one of which contained a CLASS.
  • My regex are your regex except the ABA one has an extra wrapper of () and incremented backreferences so I can use groups(1) to get the aba string without having to construct it from parts. I had to go back and add the positive lookahead because my first submission rejected overlaps, which we didn't have to worry about for ABBA.

    Day 8 was fun! I only had to add one line of code for the second part because I already had a display method for debugging. A deque might be more efficient, I suppose.
  • okeefe said:

    My regex are your regex except the ABA one has an extra wrapper of () and incremented backreferences so I can use groups(1) to get the aba string without having to construct it from parts. I had to go back and add the positive lookahead because my first submission rejected overlaps, which we didn't have to worry about for ABBA.

    Day 8 was fun! I only had to add one line of code for the second part because I already had a display method for debugging. A deque might be more efficient, I suppose.
    I also thought about using a deque because it comes with a rotation function builtin, but I just used the old chop and swap instead.
  • “That looks unpythonic.” → Discovered collections.defaultdict.
  • Anyone know any good resources for starting to build compilers or open source projects that wouldn't be too difficult to contribute to?
    Thoroughly enjoyed my compilers course and would love to continue building them. They combine all my favorite aspects of computing into one giant, horrible to debug package
  • Interpreter, rather than compiler, but I've always liked Peter Norvig's articles on it.
  • Day 11 is kicking my ass.
  • edited December 2016
    Revamped my lighting system. Now the lights will respect walls, meaning no more bleed through from neighboring halls!

    image
    Post edited by Andrew on
  • YEAH THIS SHIT IS LIT
    image
  • Those look really cool, Andrew.
  • Seriously. Good work.
  • edited December 2016
    image
    FIGHT FIGHT FIGHT
    Post edited by Andrew on
  • okeefe said:

    Day 11 is kicking my ass.

    Yeah, I know the feeling, I still haven't done it because of a few other commitments, I was thinking a dynamic programming solution with a list of changes and providing the min() of the recursive call to moving 2 chips, 2 generators or a chip and a generator, and for each loop through all possible combinations on that floor.

    Alternatively could also be reduced to a BFS or IDDLS however it's not working in my head clearly by approaching it in a newish language. Each adjacent edge would obviously be a logical possible move and each node a state for all 4 floors to be at.

    the logical check at each floor at the start of the recursion or loop would be to check (after adding elevator contents to the floor) if there are any microchips without corresponding generators and if so, if there are any generators with no corresponding microchips then that should fail.
  • I haven't had time and stopped on day 9.5. Don't scare me about day 11. They don't take this thing down, right? I can finish in January?
  • Yeah this thing escalated.
  • I might do this over the weekend. See how many I can get done quickly.
Sign In or Register to comment.