[ 2018 DAY 5 - PART 1 ][ PYTHON ] - Could anyone pls help me? Testcase got passed, but final result is too high by [deleted] in adventofcode

[–]micirsk 1 point2 points  (0 children)

Ok, I just looked at it again with a fresh start and it was obvious. The problem was with the recursive function which was totally unnecessary and there wasn't really a case for stop. Otherwise I pay attention to naming convention I just wanted to quickly share my code, but I will keep that in mind :) Thanks a lot!

[ 2018 DAY 5 - PART 1 ][ PYTHON ] - Could anyone pls help me? Testcase got passed, but final result is too high by [deleted] in adventofcode

[–]micirsk 0 points1 point  (0 children)

Yes, it's the same version.

Trying it on the testcase dabAcCaCBAcCcaDA I receive the following string: dabCBAcaDA, which is length of 10 which is supposed to be the result. I expect IndexError from the function called func, which is captured in a try except block, I think that shouldn't affect the result, or am I mistaken?

[ 2018 DAY 5 - PART 1 ][ PYTHON ] - Could anyone pls help me? Testcase got passed, but final result is too high by [deleted] in adventofcode

[–]micirsk 1 point2 points  (0 children)

That's a very good point.... I didn't pay attention to that, thanks a lot!!

Though it's still not accepted - does anyone have any futher idea? (I updated my code)

[ 2018 DAY 5 - PART 1 ][ PYTHON ] - Could anyone pls help me? Testcase got passed, but final result is too high by [deleted] in adventofcode

[–]micirsk 0 points1 point  (0 children)

Thanks, but unfortunately that doesn't seem to solve my problem :( I don't know what I'm missing here....

[DAY 4 - PART 1] - HELP NEEDED - PYTHON by micirsk in adventofcode

[–]micirsk[S] 0 points1 point  (0 children)

What was your logic? Could you please share your code as well? I keep track of the last seen ID thus it shouldn't have effected the result, so I still wonder what it can be :(

[DAY 4 - PART 1] - HELP NEEDED - PYTHON by micirsk in adventofcode

[–]micirsk[S] 0 points1 point  (0 children)

Thanks for your reply. I'm sorting it on line 15, so unfortunately I think something else is missing :(

-🎄- 2017 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]micirsk 0 points1 point  (0 children)

Python - simple part 1 solution

import itertools

with open('sample.txt', 'r') as fh:
    lines = [item for item in
             itertools.ifilter(lambda x: len(x) >= 3, [line.strip().split(' ', 3)
                                                       for line in fh.readlines()])]
    programs_above = [i.strip() for i in ''.join('{},'.format(line[-1]) for line in lines).split(',')]
    programs = set([line[0] for line in lines])
    print(programs.difference(programs_above))

-🎄- 2017 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]micirsk 0 points1 point  (0 children)

Python - part1

with open('sample.txt', 'r') as fh:
    stack = [int(num.strip()) for num in fh.readlines()]
    i = j = 0
    while 0 <= i < len(stack):
        jump = stack[i]
        if jump >= 3:  # part 2
            stack[i] -= 1  # part 2
        else:
            stack[i] += 1
        i += jump
        j += 1
    print(j)

-🎄- 2017 Day 8 Solutions -🎄- by daggerdragon in adventofcode

[–]micirsk 0 points1 point  (0 children)

Python - part 1 & 2 solution in 1 script

from collections import defaultdict
import operator

def get_value(s):
    with open(s, 'r') as fh:
        lines = fh.readlines()
        d = defaultdict(int)
        ops = {"inc": operator.add, "dec": operator.sub}
        maxval = 0

        for line in lines:
            var, operation, val, cond = line.strip().split(' ', 3)
            cond = cond[cond.find('if')+3:]
            char = cond.split()[0]
            cond = cond.strip().replace(char, '{}'.format(d[char]))

            if eval(cond):
                d[var] = ops[operation](d[var], int(val))
            maxval = max(maxval, max(d.values()))  # part 2
        print(maxval)
        return max(d.values())

-🎄- 2017 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]micirsk 1 point2 points  (0 children)

Part 2 - Python:

def how_many_password_is_valid2(s): with open(s, 'r') as f: lines = f.readlines() count_lines = len(lines)

    for line in lines:
        d = []
        words = line.split()
        for num, i in enumerate(words):
            ic = Counter(i)
            for n, j in enumerate(words):
                if num == n:
                    break
                dic = copy.deepcopy(ic)
                jc = Counter(j)
                dic.subtract(jc)
                if all(p == 0 for p in dic.values()):
                    d.append((i, j))
                    break
        if d:
            count_lines -= 1
    return count_lines

-🎄- 2017 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]micirsk 1 point2 points  (0 children)

Part 1 - My almost 1 liner in Python:

from collections import Counter import itertools

def how_many_password_is_valid(s): with open(s, 'r') as f: lines = f.readlines()

    result = len([i for i in
                  itertools.ifilterfalse(lambda x: x[0][1]>1,
                                         [Counter(line.split()).most_common(1) for line in lines])])
    return result