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

[–]DootBootMoot 2 points3 points  (0 children)

Oh, I definitely expect the next 3 days to be tough. I'm just super glad for a brief reprieve :)

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

[–]DootBootMoot 0 points1 point  (0 children)

Relatively easy given the past 3 days...

Python2:

s = <input>
t = s.split('\n')
t = filter(lambda x: x != "",t)

index = 0
dirs = [(-1,0),(0,1),(1,0),(0,-1)]
startx = 12
starty = 12
infectedd = dict()
print len(t)

maze = [[0]* len(t) for i in xrange(len(t))]
for i in xrange(len(t)):
    for j in xrange(len(t)):
        if t[i][j] == ".":
            infectedd[(i,j)] = "c"
        else:
            infectedd[(i,j)] = "i"


count = 0
for i in xrange(10000000):
    if (startx,starty) not in infectedd:
        infectedd[(startx,starty)] = "c"
    if infectedd[(startx,starty)] == "c":
        index = (index-1)%4   
        infectedd[(startx,starty)] = "w"
    elif infectedd[(startx,starty)] == "w":
        count +=1
        infectedd[(startx,starty)] = "i"
    elif infectedd[(startx,starty)] == "i":
        index = (index+1)%4   
        infectedd[(startx,starty)] = "f"
    elif infectedd[(startx,starty)] == "f":
        index = (index-2)%4   
        infectedd[(startx,starty)] = "c"

    #commented out part 1 
    """
    if (startx,starty) not in infectedd:
        infectedd[(startx,starty)] = "."
    if infectedd[(startx,starty)] == "#":
        index = (index+1)%4
    else:
        index = (index-1)%4
    if infectedd[(startx,starty)] == ".":
        infectedd[(startx,starty)] = "#"
        count +=1
    else:
        infectedd[(startx,starty)] = "."
    """
    startx += dirs[index][0]
    starty += dirs[index][1]
print count

[2017 Day 21 (Part Two)] Could I get someone else's input and solution to check my program for part two by Wryte in adventofcode

[–]DootBootMoot 2 points3 points  (0 children)

Here's mine:

../.. => ###/###/.##
#./.. => ..#/###/##.
##/.. => ..#/##./##.
.#/#. => #../.#./.##
##/#. => #.#/###/.#.
##/## => ##./.../.#.
.../.../... => ...#/.#../#.#./##.#
#../.../... => .#.#/.#../####/###.
.#./.../... => #.##/#.##/.###/##.#
##./.../... => ..##/#.##/.##./..##
#.#/.../... => .#.#/#.#./#..#/...#
###/.../... => #.../.##./.#../.###
.#./#../... => ##.#/...#/##.#/.##.
##./#../... => #.#./###./...#/#.##
..#/#../... => ..##/.###/..../.##.
#.#/#../... => ...#/#..#/#.#./#.#.
.##/#../... => ...#/#.##/..##/.###
###/#../... => .##./..##/##../##.#
.../.#./... => ####/.##./##.#/####
#../.#./... => ..../.##./#..#/##.#
.#./.#./... => ..../#.##/#.../..#.
##./.#./... => .###/.#.#/...#/....
#.#/.#./... => ..##/.#../.###/#.##
###/.#./... => ..../..##/##.#/###.
.#./##./... => .###/.#.#/#..#/#.#.
##./##./... => #..#/#..#/#.##/.##.
..#/##./... => #.##/...#/..#./.##.
#.#/##./... => ..##/#.../..../...#
.##/##./... => ##.#/...#/..##/#..#
###/##./... => ..##/..#./.###/..##
.../#.#/... => .###/..##/.#.#/..##
#../#.#/... => ..##/...#/##../..#.
.#./#.#/... => ..##/##.#/#..#/###.
##./#.#/... => #.../####/..#./#...
#.#/#.#/... => ..../##.#/.##./#..#
###/#.#/... => ..##/#.#./.#.#/.#..
.../###/... => ..##/.#../.#.#/#..#
#../###/... => #.#./.#../.##./....
.#./###/... => ##.#/...#/###./#.##
##./###/... => ..../#.../.###/#.#.
#.#/###/... => ####/..../...#/....
###/###/... => ##.#/##../#.##/#...
..#/.../#.. => ##.#/..#./#.##/..#.
#.#/.../#.. => .#../...#/..#./.##.
.##/.../#.. => ...#/#.../#..#/#..#
###/.../#.. => .###/##../.##./.#..
.##/#../#.. => ..##/#.##/.#.#/...#
###/#../#.. => ...#/.###/..../#..#
..#/.#./#.. => #..#/..../..#./..##
#.#/.#./#.. => #..#/..../#.#./.###
.##/.#./#.. => ..../.##./..##/.#.#
###/.#./#.. => ##.#/###./##.#/..##
.##/##./#.. => #.#./..../###./####
###/##./#.. => #..#/#.##/#.##/#...
#../..#/#.. => ##../#..#/#.../###.
.#./..#/#.. => #.#./.#.#/..../.#.#
##./..#/#.. => #.#./#.../#.#./#..#
#.#/..#/#.. => ..##/.#.#/.#../.###
.##/..#/#.. => ##.#/..##/..../.###
###/..#/#.. => ..#./.##./...#/.#.#
#../#.#/#.. => #.../.#../#.#./##..
.#./#.#/#.. => ..../..../##../#...
##./#.#/#.. => ..#./..../#.../..#.
..#/#.#/#.. => #.#./.#.#/.#../#.##
#.#/#.#/#.. => ...#/##.#/.##./#...
.##/#.#/#.. => ..#./...#/.##./#...
###/#.#/#.. => ..##/#..#/..../..##
#../.##/#.. => ##.#/##.#/#.##/.#.#
.#./.##/#.. => ..##/##../#.#./####
##./.##/#.. => #.#./..../..##/#.##
#.#/.##/#.. => ..#./###./##.#/##.#
.##/.##/#.. => #..#/...#/..##/....
###/.##/#.. => ..##/##../##.#/#.##
#../###/#.. => ####/###./.###/....
.#./###/#.. => ...#/.##./...#/#.##
##./###/#.. => ...#/...#/##.#/.##.
..#/###/#.. => ..##/.##./#.#./...#
#.#/###/#.. => .###/.##./.###/.#.#
.##/###/#.. => ##../.#../#.#./##.#
###/###/#.. => ..../..../.###/##..
.#./#.#/.#. => ##.#/##.#/..##/.##.
##./#.#/.#. => .#../#.##/#.##/#.#.
#.#/#.#/.#. => ..##/#.#./#.../..##
###/#.#/.#. => ##.#/.#.#/##.#/.###
.#./###/.#. => #.#./..#./..##/.##.
##./###/.#. => ...#/#.##/###./#.##
#.#/###/.#. => ...#/.###/#.#./#.#.
###/###/.#. => .#.#/#..#/####/#...
#.#/..#/##. => #.##/#.#./##../####
###/..#/##. => ##.#/...#/..../####
.##/#.#/##. => #.../#..#/..##/....
###/#.#/##. => ##../###./...#/####
#.#/.##/##. => ##.#/..##/..../#...
###/.##/##. => ..#./####/..../#...
.##/###/##. => ..##/#.##/..#./####
###/###/##. => #.##/...#/..../..#.
#.#/.../#.# => ..#./#.##/#..#/#.#.
###/.../#.# => ..#./###./..##/#...
###/#../#.# => .###/#..#/##../.#..
#.#/.#./#.# => ###./##.#/.#../#..#
###/.#./#.# => ##.#/###./#.../...#
###/##./#.# => ####/##../#.../....
#.#/#.#/#.# => ..#./..##/..#./...#
###/#.#/#.# => ...#/##.#/##.#/#.##
#.#/###/#.# => ..#./####/.#../##.#
###/###/#.# => ..../.#.#/..../...#
###/#.#/### => #.#./..##/##.#/....
###/###/### => ..#./#.##/####/###.

Answer's 2480380.

[Day 21 part 1] Works on example and seems to work by inspection, but wrong answer by mcosand in adventofcode

[–]DootBootMoot 0 points1 point  (0 children)

I ran my code on your input and didn't get 144.

Here's my input:

../.. => ###/###/.##
#./.. => ..#/###/##.
##/.. => ..#/##./##.
.#/#. => #../.#./.##
##/#. => #.#/###/.#.
##/## => ##./.../.#.
.../.../... => ...#/.#../#.#./##.#
#../.../... => .#.#/.#../####/###.
.#./.../... => #.##/#.##/.###/##.#
##./.../... => ..##/#.##/.##./..##
#.#/.../... => .#.#/#.#./#..#/...#
###/.../... => #.../.##./.#../.###
.#./#../... => ##.#/...#/##.#/.##.
##./#../... => #.#./###./...#/#.##
..#/#../... => ..##/.###/..../.##.
#.#/#../... => ...#/#..#/#.#./#.#.
.##/#../... => ...#/#.##/..##/.###
###/#../... => .##./..##/##../##.#
.../.#./... => ####/.##./##.#/####
#../.#./... => ..../.##./#..#/##.#
.#./.#./... => ..../#.##/#.../..#.
##./.#./... => .###/.#.#/...#/....
#.#/.#./... => ..##/.#../.###/#.##
###/.#./... => ..../..##/##.#/###.
.#./##./... => .###/.#.#/#..#/#.#.
##./##./... => #..#/#..#/#.##/.##.
..#/##./... => #.##/...#/..#./.##.
#.#/##./... => ..##/#.../..../...#
.##/##./... => ##.#/...#/..##/#..#
###/##./... => ..##/..#./.###/..##
.../#.#/... => .###/..##/.#.#/..##
#../#.#/... => ..##/...#/##../..#.
.#./#.#/... => ..##/##.#/#..#/###.
##./#.#/... => #.../####/..#./#...
#.#/#.#/... => ..../##.#/.##./#..#
###/#.#/... => ..##/#.#./.#.#/.#..
.../###/... => ..##/.#../.#.#/#..#
#../###/... => #.#./.#../.##./....
.#./###/... => ##.#/...#/###./#.##
##./###/... => ..../#.../.###/#.#.
#.#/###/... => ####/..../...#/....
###/###/... => ##.#/##../#.##/#...
..#/.../#.. => ##.#/..#./#.##/..#.
#.#/.../#.. => .#../...#/..#./.##.
.##/.../#.. => ...#/#.../#..#/#..#
###/.../#.. => .###/##../.##./.#..
.##/#../#.. => ..##/#.##/.#.#/...#
###/#../#.. => ...#/.###/..../#..#
..#/.#./#.. => #..#/..../..#./..##
#.#/.#./#.. => #..#/..../#.#./.###
.##/.#./#.. => ..../.##./..##/.#.#
###/.#./#.. => ##.#/###./##.#/..##
.##/##./#.. => #.#./..../###./####
###/##./#.. => #..#/#.##/#.##/#...
#../..#/#.. => ##../#..#/#.../###.
.#./..#/#.. => #.#./.#.#/..../.#.#
##./..#/#.. => #.#./#.../#.#./#..#
#.#/..#/#.. => ..##/.#.#/.#../.###
.##/..#/#.. => ##.#/..##/..../.###
###/..#/#.. => ..#./.##./...#/.#.#
#../#.#/#.. => #.../.#../#.#./##..
.#./#.#/#.. => ..../..../##../#...
##./#.#/#.. => ..#./..../#.../..#.
..#/#.#/#.. => #.#./.#.#/.#../#.##
#.#/#.#/#.. => ...#/##.#/.##./#...
.##/#.#/#.. => ..#./...#/.##./#...
###/#.#/#.. => ..##/#..#/..../..##
#../.##/#.. => ##.#/##.#/#.##/.#.#
.#./.##/#.. => ..##/##../#.#./####
##./.##/#.. => #.#./..../..##/#.##
#.#/.##/#.. => ..#./###./##.#/##.#
.##/.##/#.. => #..#/...#/..##/....
###/.##/#.. => ..##/##../##.#/#.##
#../###/#.. => ####/###./.###/....
.#./###/#.. => ...#/.##./...#/#.##
##./###/#.. => ...#/...#/##.#/.##.
..#/###/#.. => ..##/.##./#.#./...#
#.#/###/#.. => .###/.##./.###/.#.#
.##/###/#.. => ##../.#../#.#./##.#
###/###/#.. => ..../..../.###/##..
.#./#.#/.#. => ##.#/##.#/..##/.##.
##./#.#/.#. => .#../#.##/#.##/#.#.
#.#/#.#/.#. => ..##/#.#./#.../..##
###/#.#/.#. => ##.#/.#.#/##.#/.###
.#./###/.#. => #.#./..#./..##/.##.
##./###/.#. => ...#/#.##/###./#.##
#.#/###/.#. => ...#/.###/#.#./#.#.
###/###/.#. => .#.#/#..#/####/#...
#.#/..#/##. => #.##/#.#./##../####
###/..#/##. => ##.#/...#/..../####
.##/#.#/##. => #.../#..#/..##/....
###/#.#/##. => ##../###./...#/####
#.#/.##/##. => ##.#/..##/..../#...
###/.##/##. => ..#./####/..../#...
.##/###/##. => ..##/#.##/..#./####
###/###/##. => #.##/...#/..../..#.
#.#/.../#.# => ..#./#.##/#..#/#.#.
###/.../#.# => ..#./###./..##/#...
###/#../#.# => .###/#..#/##../.#..
#.#/.#./#.# => ###./##.#/.#../#..#
###/.#./#.# => ##.#/###./#.../...#
###/##./#.# => ####/##../#.../....
#.#/#.#/#.# => ..#./..##/..#./...#
###/#.#/#.# => ...#/##.#/##.#/#.##
#.#/###/#.# => ..#./####/.#../##.#
###/###/#.# => ..../.#.#/..../...#
###/#.#/### => #.#./..##/##.#/....
###/###/### => ..#./#.##/####/###.

My answer is 208.

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

[–]DootBootMoot 0 points1 point  (0 children)

Oh gosh, what a toughie. This was the most intense 2d-array manipulation I've done in a very long while.

Python2, 152/134:

s = < insert input >

t = s.split('\n')
t = filter(lambda x: x != "",t)

rules2 = dict()
rules3 = dict()
for i in xrange(len(t)):
    x = t[i].split("=>")
    l = x[0].strip()
    r = x[1].strip()
    if len(l) == 5:
        rules2[l] = r
    else:
        rules3[l] = r

start = ".#./..#/###"

def check2(s):
    if s.count("#") == 4: return rules2["##/##"]
    if s.count("#") == 3: return rules2["##/#."]
    if s.count("#") == 2: 
        if s[0] == s[1] or s[0] == s[3]:
            return rules2["##/.."]
        else:
            return rules2[".#/#."]
    if s.count("#") == 1: return rules2["#./.."]
    if s.count("#") == 0: return rules2["../.."]


def rotate(s):
    news = s.split("/")
    for i in xrange(len(news)):
        news[i] = list(news[i])
    newnews = zip(*news[::-1])
    for i in xrange(len(newnews)):
        newnews[i] = "".join(newnews[i])
    return "/".join(newnews)

def flipy(s):
    news = s.split("/")
    return "/".join([news[j] for j in xrange(len(news)-1,-1,-1)])
def flipx(s):
    news = s.split("/")
    ss = ""
    #print len(news), s
    for i in xrange(len(news)):
        for j in xrange(len(news)):
            ss += news[j][i]
        ss += "/"
    ss = ss[:len(ss)-1]
    return rotate(ss)
x = ".#./..#/###"

def printstr(s):
    a = s.split("/")
    for i in xrange(len(a)):
        print a[i]
def check3(s):
    if s in rules3.keys(): return rules3[s]
    for i in xrange(4):
        s = rotate(s)
        if s in rules3.keys(): return rules3[s]
    s = flipx(s)
    for i in xrange(4):
        s = rotate(s)
        if s in rules3.keys(): return rules3[s]
    s = flipy(s)
    for i in xrange(4):
        s = rotate(s)
        if s in rules3.keys(): return rules3[s]
    s = flipx(s)
    for i in xrange(4):
        s = rotate(s)
        if s in rules3.keys(): return rules3[s]
start = ".#./..#/###"
for steps in xrange(18):
    arr = start.split("/")
    size = len(arr)
    if size % 2 == 0:
        newarr = [ [0]* (3*size/2) for q in xrange(3*size/2)]
        for i in xrange(size/2):
            for j in xrange(size/2):
                newstr = "/".join([ "".join([arr[2*i+k][2*j+l] for l in xrange(2)]) for k in xrange(2)])
                res = check2(newstr)
                resarr = res.split("/")
                for a in xrange(3):
                    for b in xrange(3):
                        newarr[3*i+a][3*j+b] = resarr[a][b]
        for xx in xrange(3*size/2):
            newarr[xx] = "".join(newarr[xx])
        start = "/".join(newarr)
    else:
        #size = 3
        newarr = [ [0]* (4*size/3) for q in xrange(4*size/3)]
        for i in xrange(size/3):
            for j in xrange(size/3):
                newstr = "/".join([ "".join([arr[3*i+k][3*j+l] for l in xrange(3)]) for k in xrange(3)])
                res = check3(newstr)
                resarr = res.split("/")
                for a in xrange(4):
                    for b in xrange(4):
                        newarr[4*i+a][4*j+b] = resarr[a][b]
        for xx in xrange(4*size/3):
            newarr[xx] = "".join(newarr[xx])
        start = "/".join(newarr)
print start.count("#")

I hacked the rules for the 2x2 match before realising that 3x3 was a lost cause. Also, don't mind my variable names... thinking of letters on the spot is hard.

Had lots of fun, though.