Ejemplo n.º 1
0
def main():
    seats: List[str] = [line.strip() for line in readFile(FILEPATH)]

    # Part 1
    print(f"Part 1 -- Numseats: {runUntilNoChange(seats, 4, False)}")

    # Part 2
    print(f"Part 2 -- Numseats: {runUntilNoChange(seats, 5, True)}")
Ejemplo n.º 2
0
def main():
    inputLines: List[str] = [line.strip() for line in readFile(FILEPATH)]

    # Part 1
    total: int = parseMasksForNumbers(inputLines)
    print(f"Part 1 -- Total left in memory: {total}")

    # Part 2
    total: int = parseMasksForAddresses(inputLines)
    print(f"Part 2 -- Total left in memory: {total}")
Ejemplo n.º 3
0
def main():
    numsList: List[int] = [int(s.strip()) for s in readFile(FILEPATH)]

    # Part 1
    oddball: int = findOddball(numsList, 25)
    print(f"Part 1 -- Oddball: {oddball}")

    # Part 2
    weakness: int = findEncryptionWeakness(numsList, oddball)
    print(f"Part 2 -- Encryption Weakness: {weakness}")
Ejemplo n.º 4
0
def main():
   # After completing day 24, I decided to give this puzzle another go . . .
   # Again, kudos to Jonathan Paulson for helping me understand how to approach these puzzles,
   # as in day 24.
   inputLines: List[str] = [s.strip() for s in readFile(FILEPATH)]
   
   # Part 1
   active3DSet = create3DActiveSet(inputLines)
   print(f"Part 1 -- Active 3D Cubes after 6 cycles: {countActive3DCubesAfterXCycles(active3DSet, 6)}")

   # Part 2
   active4DSet = create4DActiveSet(inputLines)
   print(f"Part 2 -- Active 4D Cubes after 6 cycles: {countActive4DCubesAfterXCycles(active4DSet, 6)}")
Ejemplo n.º 5
0
def main():
    inputLines: List[str] = [s.strip() for s in readFile(FILEPATH)]
    cardPublicKey, doorPublicKey = int(inputLines[0]), int(inputLines[1])

    # Part 1
    # This operation takes ~2 minutes, so I ran the code and hand put the values in below
    # cardLoops: int = calculateLoopSize(cardPublicKey)
    # doorLoops: int = calculateLoopSize(doorPublicKey)
    cardLoops: int = 8987376
    doorLoops: int = 14382089
    print(
        f"Part 1 -- Encryption Key: {calculateEncryptionKey(cardPublicKey, doorLoops)}"
    )
Ejemplo n.º 6
0
def main():
    fullInput: List[str] = readFile(FILEPATH)

    rules: List[str] = [s.strip() for s in fullInput[0:fullInput.index("\n")]]
    messages: List[str] = [
        s.strip() for s in fullInput[fullInput.index("\n") + 1:]
    ]

    # Part 1
    whiteFlag(1, "Num valid strings", "12/19")

    # Part 2
    whiteFlag(2, "?", "12/19")
Ejemplo n.º 7
0
def main():
    inputLines: List[str] = [line.strip() for line in readFile(FILEPATH)]
    yourTime: int = int(inputLines[0])
    onlyValidBuses: List[int] = [
        int(i) for i in inputLines[1].split(",") if i != "x"
    ]
    # Part 1
    partOne: int = calculateWeightedWaitTime(yourTime, onlyValidBuses)
    print(f"Part 1 -- Time Diff: {partOne}")

    # (my attempt at) Part 2
    fullBusSchedule: List[str] = inputLines[1].strip().split(",")
    busOrder: List[List[int]] = findBusOrder(fullBusSchedule)
    whiteFlag(2, "Special Time", "12/13")
Ejemplo n.º 8
0
def main():
    inputLines: List[str] = [s.strip() for s in readFile(FILEPATH)]

    # Part 1
    # I am honestly not sure why the function does not work. I tested it for over an hour
    # with a bunch of individual inputs, and it worked fine for every one. If anyone knows
    # why this is failing, please let me know!
    total: int = 0
    for line in inputLines:
        total += parseArithmetic(line)
    print(f"Part 1 -- Total Sum: {total}")

    # Part 2
    whiteFlag(2, "?", "12/18")
Ejemplo n.º 9
0
def main():
   # I was admittedly confused by the wording of this puzzle, so I watched this helpful video
   # to help me understand what was being asked: https://www.youtube.com/watch?v=tXwh0y0PyPw.
   # Credits to TurkeyDev YouTube for his helpful video and advice.
   
   inputLines: List[str] = [s.strip() for s in readFile(FILEPATH)]

   # Part 1
   prelimAllergenMap, allIngredients = parseAllergenAssociations(inputLines)
   finalMap: Dict[str, str] = finalizeAllergenMap(prelimAllergenMap)
   print(f"Part 1 -- Number of Non-Allergen Ingredients: {countNumNonAllergenIngredients(finalMap, allIngredients)}")

   # Part 2
   print(f"Part 2 -- Canonical Dangerous Ingredients List: {constructCanonicalDangerousIngredients(finalMap)}")
Ejemplo n.º 10
0
def main():
    lines: list = readFile(FILEPATH)
    validPasswordsOne: int = 0
    validPasswordsTwo: int = 0

    for line in lines:
        lower, upper, target, password = componentizePassword(line)
        validPasswordsOne += isValidPasswordPartOne(lower, upper, target,
                                                    password)
        validPasswordsTwo += isValidPasswordPartTwo(lower, upper, target,
                                                    password)

    print(f"Number of valid passwords for part 1: {validPasswordsOne}")
    print(f"Number of valid passwords for part 2: {validPasswordsTwo}")
Ejemplo n.º 11
0
def main():
    adapters: List[int] = [int(s.strip()) for s in readFile(FILEPATH)]
    adapters.append(0)  # outlet
    adapters.sort()

    # Part 1
    diff: int = calculateVoltageDifference(adapters)
    print(f"Part 1 -- Diff: {diff}")

    # Part 2
    # I was stumped on this problem, so I looked up a video to help me understand dynamic programming,
    # something I have never learned or tackled before. This video is what helped me solve the problem:
    # https://www.youtube.com/watch?v=eeYanhLamjg.
    numWays: int = countValidArrangements(adapters)
    print(f"Part 2 -- Numways: {numWays}")
Ejemplo n.º 12
0
def main():
    inputLines: List[str] = [s.strip() for s in readFile(FILEPATH)]
    tiles: List[Tuple[int, int,
                      int]] = [tokenizeHexString(line) for line in inputLines]

    # Part 1
    blackTiles = createBlackTilesSet(tiles)
    print(f"Part 1 -- Number of black tiles: {len(blackTiles)}")

    # Part 2
    # I was very close to the solution on my 2nd attempt, and this YouTube video gave me the
    # push I needed: https://www.youtube.com/watch?v=xNv7d2crKoc; thanks to Jonathan Paulson!
    blackTiles = flipTiles(blackTiles, 100)
    print(
        f"Part 2 -- Number of black tiles after 100 days of art exhibition: {len(blackTiles)}"
    )
Ejemplo n.º 13
0
def populateDictWithNumbers(filename: str) -> dict:
    """
   Opens a file consisting of numbers and populates and returns a dictionary/hash set containing them
   """

    numsDict: dict = {}

    try:
        numsList: list = readFile(filename)

        for num in numsList:
            key = int(num)
            numsDict.setdefault(key, 1)

        return numsDict
    except:
        raise Exception(f"Could not load file at {filename}")
Ejemplo n.º 14
0
def main():
   instructions: List[str] = [i.strip() for i in readFile(FILEPATH)]

   # Part 1
   boat: Ferry = Ferry(Direction.EAST, 0, 0)
   for i in instructions:
      boat.consumeInstruction(i)
   print(f"Part 1 -- Manhattan Distance: {boat.calculateManhattanDistance()}")

   # Part 2
   boat = Ferry(Direction.EAST, 0, 0)
   wayPoint: Waypoint = Waypoint(10, 1)
   for i in instructions:
      if i[0] == Direction.FORWARD.value:
         boat.moveRelativeToWaypoint(int(i[1:]), wayPoint.horiz, wayPoint.vert)
      else:
         wayPoint.consumeWaypointInstruction(i)
   print(f"Part 2 -- Manhattan Distance: {boat.calculateManhattanDistance()}")
Ejemplo n.º 15
0
def createPassportList(filepath: str) -> List[str]:
   """
   Reads an input batch file and outputs a list of concatenated passports
   """
   inputLines: List[str] = readFile(filepath)
   passportList: List[str] = []

   tempPassport: str = ""
   for line in inputLines:
      if line == "\n":
         if tempPassport != "":
            tempPassport = tempPassport.replace(" ", "\n").strip()
            passportList.append(tempPassport)
         tempPassport = ""
      else:
         tempPassport += " " + line
   passportList.append(tempPassport) # don't forget last one!

   return passportList
Ejemplo n.º 16
0
def main():
    # Capture input
    bagInput: List[str] = readFile(FILEPATH)
    bagMap: Dict[str, List[str]] = {}

    # Populate hash map of bags
    for s in bagInput:
        bagMap.update(createBagMap(s, False))

    # Part 1
    count = 0
    for key in bagMap.keys():
        count += containsShinyGoldBag(key, bagMap)
    print(f"Part 1 -- Shiny Gold Bag count: {count - 1}")

    # Part 2
    bagMap = bagMap.clear()
    bagMap = {}
    for s in bagInput:
        bagMap.update(createBagMap(s, True))
    numBagsWithin: int = countNumBagsWithin("shiny gold bag", bagMap)
    print(f"Part 2 -- number of bags within Shiny Gold Bag: {numBagsWithin}")
Ejemplo n.º 17
0
def main():
    inputLine: str = readFile(FILEPATH)[0]
    game: Cups = Cups(inputLine)

    # Part 1
    game.move(100)
    print(f"Part 1 -- Cups order after cup #1: {game.stringify(1)[1:]}")

    # Part 2
    # This algorithm is sound, but it takes a LONG TIME . . .
    # Thus, I wasn't able to get the answer in reasonable time. I will find a way to speed it up.
    millionCups: List[int] = []
    for ch in inputLine:
        millionCups.append(int(ch))
    for i in range(len(millionCups) + 1, 1000001, 1):
        millionCups.append(i)

    game.replaceCups(millionCups)
    # game.move(10000000)
    print(
        f"Part 2 -- 2 cups after cup #1: {game.getTwoAfterX(1)} <- this is wrong (my current algo takes too long)"
    )
Ejemplo n.º 18
0
def createTicketList(filename:str) -> List[str]:
   """
   Returns a list of tickets from a file
   """
   return [line.strip() for line in readFile(filename)]
Ejemplo n.º 19
0
def buildMountain(filename: str) -> List[str]:
    """
   Constructs the mountain based on file input
   """
    return [line.strip() for line in readFile(filename)]