Ejemplo n.º 1
0
def lightGrid(s):
    lines = s.split("\n")
    matrix = [[False for x in xrange(1000)] for x in xrange(1000)]

    for l in lines:
        command = l.split(" ")

        if len(command) == 4:
            start = command[1].split(",")
            end = command[3].split(",")

            toggleLights(start, end, matrix)
        elif command[1] == "on":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOnLights(start, end, matrix)
        elif command[1] == "off":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOffLights(start, end, matrix)

    lightsOn = 0

    for i in xrange(1000):
        for j in xrange(1000):
            if matrix[i][j]:
                lightsOn += 1

    return "There are %d lights lit." % lightsOn
Ejemplo n.º 2
0
def lightGrid(s):
    lines = s.split("\n")
    matrix = [[False for x in xrange(1000)] for x in xrange(1000)]

    for l in lines:
        command = l.split(" ")

        if len(command) == 4:
            start = command[1].split(",")
            end = command[3].split(",")

            toggleLights(start, end, matrix)
        elif command[1] == "on":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOnLights(start, end, matrix)
        elif command[1] == "off":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOffLights(start, end, matrix)

    lightsOn = 0

    for i in xrange(1000):
        for j in xrange(1000):
            if matrix[i][j]:
                lightsOn += 1

    return "There are %d lights lit." %lightsOn
Ejemplo n.º 3
0
def lightGrid(s):
    lines = s.split("\n")
    matrix = [[0 for x in xrange(1000)] for x in xrange(1000)]

    for l in lines:
        command = l.split(" ")

        if len(command) == 4:
            start = command[1].split(",")
            end = command[3].split(",")

            toggleLights(start, end, matrix)
        elif command[1] == "on":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOnLights(start, end, matrix)
        elif command[1] == "off":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOffLights(start, end, matrix)

    totalBrightness = 0

    for i in xrange(1000):
        for j in xrange(1000):
            if matrix[i][j]:
                totalBrightness += matrix[i][j]

    return "The total brightness of all lights is %d." % totalBrightness
Ejemplo n.º 4
0
def lightGrid(s):
    lines = s.split("\n")
    matrix = [[0 for x in xrange(1000)] for x in xrange(1000)]

    for l in lines:
        command = l.split(" ")

        if len(command) == 4:
            start = command[1].split(",")
            end = command[3].split(",")

            toggleLights(start, end, matrix)
        elif command[1] == "on":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOnLights(start, end, matrix)
        elif command[1] == "off":
            start = command[2].split(",")
            end = command[4].split(",")

            turnOffLights(start, end, matrix)

    totalBrightness = 0

    for i in xrange(1000):
        for j in xrange(1000):
            if matrix[i][j]:
                totalBrightness += matrix[i][j]

    return "The total brightness of all lights is %d." % totalBrightness