Example #1
0
def part1(data):
    allRows = splitFileByNewLine(data)
    updatedRows = allRows[:]
    tempRows = allRows[:]
    seatsUpdated = 1
    test = 0
    while seatsUpdated > 0:
        seatsUpdated = 0
        rowIndex = 0
        tempHolder = tempRows[:]
        for row in updatedRows:
            seatIndex = 0
            tempRow = row[:]
            for seat in tempRow:
                response = newSeatStatus(
                    seat, countAdjacent(rowIndex, seatIndex, updatedRows), 4)
                splitted = list(tempRow)
                splitted[seatIndex] = response[0]
                tempRow = "".join(splitted)
                seatsUpdated += response[1]
                seatIndex += 1
            tempHolder[rowIndex] = tempRow
            rowIndex += 1
        updatedRows = tempHolder
        test += 1
    count = 0
    for row in updatedRows:
        for i in row:
            if i == "#":
                count += 1
    return count
Example #2
0
def part1(data):
  data_array = [int(i) for i in splitFileByNewLine(data)]
  for value in data_array:
    compliment = targetSum - int(value)
    if compliment in data_array:
      return value * compliment
  return "No 2 numbers add to " + str(targetSum)
Example #3
0
def part1(data):
    highestSeat = 0
    for seat in splitFileByNewLine(data):
        seatNum = seatNumber(seat)
        if seatNum > highestSeat:
            highestSeat = seatNum
    print(highestSeat)
Example #4
0
def setup(data):
    tree = {}
    allRules = splitFileByNewLine(data)
    for rule in allRules:
        bag_color = re.match('(.+?) bags', rule).group(1)
        bag_contains = re.findall('(\d+) (.+?) bag', rule)
        tree[bag_color] = bag_contains
    return tree
Example #5
0
def part2(data):
    total = 0
    data_array = splitFileByNewLine(data)
    for item in data_array:
        x = re.search("(\d+)-(\d+)\s([a-z]):\s([a-z]+)", item)
        if x:
            if (x[4][int(x[1]) - 1] == x[3]) != (x[4][int(x[2]) - 1] == x[3]):
                total += 1
    return total
Example #6
0
def part2(data):
    allSeats = []
    for i in range(8, 127 * 8 + 7):
        allSeats.append(i)
    for seat in splitFileByNewLine(data):
        allSeats.remove(seatNumber(seat))
    for seat in allSeats:
        if (seat + 1) not in allSeats and (seat - 1) not in allSeats:
            print(seat)
Example #7
0
def part1(data):
    total = 0
    data_array = splitFileByNewLine(data)
    for item in data_array:
        x = re.search("(\d+)-(\d+)\s([a-z]):\s([a-z]+)", item)
        if x:
            count = len(re.findall(x[3], x[4]))
            if count in range(int(x[1]), int(x[2]) + 1):
                total += 1
    return total
Example #8
0
def part2(data):
  temp = 0
  data_array = [int(i) for i in splitFileByNewLine(data)]
  for value1 in data_array:
    for value2 in data_array:
      temp = value1 + value2
      value3target = targetSum - temp
      if value3target in data_array:
        print(value1 * value2 * value3target)
        return
  return "No 3 numbers add to " + str(targetSum)
Example #9
0
def part2(data):
    map = splitFileByNewLine(data)
    return countTrees(map, 1, 1) * countTrees(map, 3, 1) * countTrees(
        map, 5, 1) * countTrees(map, 7, 1) * countTrees(map, 1, 2)
Example #10
0
def part1(data):
    return countTrees(splitFileByNewLine(data), 3, 1)