예제 #1
0
def extract_input(fichier):

    lines = fileManipulation.read_file_line_by_line(fichier)
    drawNumbersList = get_draw_numbers_list(lines)
    grids = extract_grids(lines[2:])

    return (drawNumbersList, grids)
예제 #2
0
def main(fichier):

    instructions = fileManipulation.read_file_line_by_line(fichier)
    position = (0, 0, 0)
    for i in instructions:
        position = calcul_position(i, position[0], position[1], position[2])

    return position[0] * position[1]
예제 #3
0
def get_vents(filename):

    lines = fileManipulation.read_file_line_by_line(filename)
    vents = []
    for l in lines:
        vents.append(string_to_vent(l))

    return vents
예제 #4
0
def test_read_file_line_by_line_fichier_entier_est_lu():
    # Given
    filename = "input.txt"

    # When
    resultat = fileManipulation.read_file_line_by_line(filename)

    # Then
    assert resultat == ['Ligne 1', 'Ligne 2', 'Ligne 3', 'Ligne 4']
예제 #5
0
def test_read_file_line_by_line_nombre_de_lignes_est_correct():
    # Given
    filename = "input.txt"

    # When
    resultat = fileManipulation.read_file_line_by_line(filename)

    # Then
    assert len(resultat) == 4
예제 #6
0
def test_read_file_line_by_line_ligne_1_est_bien_lue():
    # Given
    filename = "input.txt"

    # When
    resultat = fileManipulation.read_file_line_by_line(filename)

    # Then
    assert resultat[0].strip() == "Ligne 1"
예제 #7
0
def main(fichier):

    lanternFishLine = fileManipulation.read_file_line_by_line(fichier)[0]
    lanternFishList = []
    for l in lanternFishLine.split(','):
        lanternFishList.append(int(l))

    for i in range(0, 80):
        lanternFishList = update_lanternfish_list(lanternFishList)

    return len(lanternFishList)
예제 #8
0
def create_map(fichier):

    lineFile = fileManipulation.read_file_line_by_line(fichier)
    outputMap = []
    for l in lineFile:
        currentLine = []
        for c in l:
            currentLine.append(int(c))
        outputMap.append(currentLine)

    return outputMap
예제 #9
0
def calcul_CO2_scrubber_rating(fichier):

    lignes = fileManipulation.read_file_line_by_line(fichier)
    colonneCourante = 0

    while len(lignes) > 1:
       colonnes = line_to_col(lignes)
       bitCommun = str(abs(int(plus_commun_bit(colonnes[colonneCourante])) -1))
       lignes = calcul_filtre_numbers(lignes, bitCommun, colonneCourante)
       colonneCourante += 1

    return lignes[0]
예제 #10
0
def calcul_oxygen_generator_rating(fichier):

    lignes = fileManipulation.read_file_line_by_line(fichier)
    colonneCourante = 0

    while len(lignes) > 1:
       colonnes = line_to_col(lignes)
       bitCommun = plus_commun_bit(colonnes[colonneCourante]) 
       lignes = calcul_filtre_numbers(lignes, bitCommun, colonneCourante)
       colonneCourante += 1

    return lignes[0]
예제 #11
0
def main(fichier):

    crabsListStr = fileManipulation.read_file_line_by_line(fichier)[0].split(',')
    crabsListInt = []
    for i in crabsListStr:
        crabsListInt.append(int(i))

    crabsListPosition = list_crabs(crabsListInt)
    crabsListBestPosition = find_best_position(crabsListPosition)
    crabsTotalFuel = compute_total_fuel(crabsListPosition,crabsListBestPosition)

    return crabsTotalFuel
예제 #12
0
def main(fichier):

    lines = fileManipulation.read_file_line_by_line(fichier)

    total = 0

    for l in lines:
        outputDigits = ""
        for c in get_output_digits(l):
            outputDigits += str(c)
        total += int(outputDigits)

    return total
예제 #13
0
def main(fichier):

    matrix = fileManipulation.read_file_line_by_line(fichier)

    sumLowest = 0

    for x in range(0, len(matrix[0])):
        for y in range(0, len(matrix)):
            if is_lowest(matrix, x, y):
                # print("x=" + str(x) + " y=" + str(y) + " xy=" + str(matrix[y][x]))
                # print(return_adjacent(matrix, x, y))
                sumLowest += (int(matrix[y][x]) + 1)

    return sumLowest
예제 #14
0
def main(fichier):

    lanternFishLine = fileManipulation.read_file_line_by_line(fichier)[0]
    lanternFishList = []
    for l in lanternFishLine.split(','):
        lanternFishList.append(int(l))

    lanternFishList = convert_lantern_fish_list(lanternFishList)

    for i in range(0, 256):
        lanternFishList = update_lanternfish_list(lanternFishList)

    sumOfFish = 0
    for i in lanternFishList:
        sumOfFish += i

    return sumOfFish
예제 #15
0
def main(fichier):

    lines = fileManipulation.read_file_line_by_line(fichier)
    allSizes = get_all_values_sizes(lines)

    return allSizes.count(2) + allSizes.count(3) + allSizes.count(4) + allSizes.count(7)