def main(stdscreen, ):
    inp = readInput()
    # inp = """"""
    
    ## Update for input specifics ##############################################
    parseInp = fileParse(inp, ff=lambda x:tuple(map(int, x.split(','))))

    print("Input is '" + str(parseInp[:10])[:100] + 
          ('...' if len(parseInp)>10 or len(str(parseInp[:10]))>100 else '') + "'")

    print("Solution to part 1: {}".format(part1(parseInp)))
    print("Solution to part 2: {}".format(part2(parseInp, stdscreen)))
from aocbase import readInput
import re

inp = readInput()


#inp = "dabAcCaCBAcCcaDA"
def estrip(inp):
    change = True
    s = list(inp)
    while change:
        change = False
        i = 0
        n = []
        skip = False
        for c1, c2 in zip(s, s[1:] + [' ']):
            if skip == True:
                skip = False
                continue
            if c1 != c2 and c1.lower() == c2.lower():
                skip = True
                change = True
            else:
                n.append(c1)
        s = n
    return s


resPolymer = estrip(inp)
print("Solution to day 5 part 1: {}".format(len(resPolymer)))
Exemple #3
0
                if getPos(r - 1, c, maze) != ' ':
                    dc = 0
                    dr = -1
                if getPos(r + 1, c, maze) != ' ':
                    if dr == -1:
                        print('Fork')
                    else:
                        dc = 0
                        dr = 1
            r += dr
            c += dc
        else:
            return s


inp = ' ' * 131 + readInput()
ex = '''     |          
     |  +--+    
     A  |  C    
 F---|----E|--+ 
     |  |  |  D 
     +B-+  +--+ '''


def makeMaze(inp):
    maze = {}
    row = 0
    for line in inp.splitlines():
        col = 0
        for pos in line:
            if pos != ' ':
Exemple #4
0
def fitsInConstellation(star1, con):
    for star2 in con:
        if sum(map(lambda x, y: abs(x - y), star1, star2)) < 4:
            return True
    return False


def mergeConstellations(constellations, toMerge):
    newConstellation = []
    while len(toMerge) > 0:
        theConstellation = toMerge.pop()
        newConstellation.extend(theConstellation)
        constellations.remove(theConstellation)
    constellations.append(newConstellation)


def clusterStars(stars):
    constellations = []
    for star in stars:
        constellations.append([star])
        matchingConstellations = []
        for constellation in constellations:
            if fitsInConstellation(star, constellation):
                matchingConstellations.append(constellation)
        mergeConstellations(constellations, matchingConstellations)
    return constellations


stars = parse(readInput())
constellations = clusterStars(stars)
print("Solution to day 25 part 1:", len(constellations))