Esempio n. 1
0
 def main():
     numbers = load_ints("input/d01.txt")
     print(count_increases(numbers))
     print(count_trios(numbers))
Esempio n. 2
0
def load_adapters(path):
    adapters = load_ints(path)
    adapters.append(0)
    adapters.sort()
    adapters.append(adapters[-1] + 3)
    return adapters
Esempio n. 3
0
 def test_load_negativeInts(self):
     ints = load_ints(GetTestFilePath("input/ints/negativeInts"))
     self.assertListEqual(
         ints, [
             50962, 126857, -127476, 136169, -62054, 116866, 123235])
Esempio n. 4
0
 def test_detect_floats(self):
     with self.assertRaises(ValueError) as context:
         load_ints(GetTestFilePath("input/ints/hasFloat"))
Esempio n. 5
0
 def test_load_ints(self):
     ints = load_ints(GetTestFilePath("input/ints/123"))
     self.assertListEqual(ints, [1, 2, 3])
Esempio n. 6
0
 def test_load_biggerInts(self):
     ints = load_ints(GetTestFilePath("input/ints/biggerInts"))
     self.assertListEqual(
         ints, [
             50962, 126857, 127476, 136169, 62054, 116866, 123235])
Esempio n. 7
0
 def main():
     values = load_ints("input/d09.txt")
     invalid_number = part_one(values, 25)
     print(invalid_number)
     print(part_two(values, invalid_number))
Esempio n. 8
0
 def test_Example1(self):
     path = GetTestFilePath("samples/d09/example1")
     values = load_ints(path)
     self.assertEqual(part_one(values, 5), 127)
Esempio n. 9
0
 def main():
     numbers = load_ints("input/d01.txt")
     print(find_product(numbers))
     print(find_trio_product(numbers))
Esempio n. 10
0
 def test_Sample(self):
     numbers = load_ints(get_test_file_path("samples/d01.txt"))
     self.assertEqual(count_increases(numbers), 7)
Esempio n. 11
0
def calc_rocket_fuel(mass):
    total_fuel = 0
    fuel = calc_fuel(mass)
    while fuel != 0:
        total_fuel += fuel
        fuel = calc_fuel(fuel)

    return total_fuel


def calc_total_fuel(masses):
    fuel = 0
    for mass in masses:
        fuel += calc_fuel(mass)

    return fuel


def total_rocket_fuel(masses):
    fuel = 0
    for mass in masses:
        fuel += calc_rocket_fuel(mass)

    return fuel


if __name__ == "__main__":
    print(calc_total_fuel(load_ints("input/d01.txt")))
    print(total_rocket_fuel(load_ints("input/d01.txt")))