Beispiel #1
0
def main():
    input_data = get_input_data(3)
    n_trees = count_trees_in_path(input_data)
    logger.info(f'Solution 3a: {n_trees}')

    n_trees_list = [count_trees_in_path(input_data, x, y) for x, y in SLOPE_INCREMENTS]
    n_trees_product = multiply(n_trees_list)
    logger.info(f'Solution 3b: {n_trees_product}')
Beispiel #2
0
    def testMultiply(self):
        nonechk = True

        self.result = math.multiply(10, 9)

        if self.result > 100:
            nonechk = None

        # 결과 값이 None 여부 확인
        self.assertIsNone(nonechk)
Beispiel #3
0
def multiply_corner_tile_ids():
  tiled_image = parse_tiled_image()
  high = sqrt(len(tiled_image)) - 1

  return multiply([
    tiled_image[0, 0].id,
    tiled_image[0, high].id,
    tiled_image[high, 0].id,
    tiled_image[high, high].id
  ])
Beispiel #4
0
infile = open('day1-input', 'r')

# our report is a list of all of the numbers in the file, with line breaks removed
report = [int(line.strip()) for line in infile]

infile.close()


# part 1
# I iterate through the cartesian product of the report with itself,
# which is to say, I iterate through every possible pairing of a number
# another in the report, and check that they sum to 2020, if so, return
# their (arithmetic) product and exit the loop
for pair in product(report, repeat = 2):
    if sum(pair) == 2020:
        print(multiply(pair))
        break

# part 2
# same as part 1 but with 3 copies of report
for trio in product(report, repeat = 3):
    if sum(trio) == 2020:
        print(multiply(trio))
        break


# for fun, here's a function that'll do the above for any number of elements n
def tuple_sum_to(l: Iterable, n: int, target) -> Union[tuple, None]:
    for t in product(l, repeat = n):
        if sum(t) == target:
            return t
Beispiel #5
0
 def rod_weight(): 
     math.multiply(float(rod_mass * g))
     return value
Beispiel #6
0
def multiply_corner_tile_ids():
  tiles = list(parse_tiles(input_))
  matched = get_matched_tiles(tiles)

  assert len(matched[N_CORNER]) == 4
  return multiply(tile.id for tile, _ in matched[N_CORNER])
Beispiel #7
0
def attributeBreak():
    import math
    math.multiply(4,5)
Beispiel #8
0
            j -= 1  # subtract something
        elif current < goal:
            i += 1  # add something
        else:
            break

        if j < 0 or i >= len(input):
            raise Exception()

    return input[i], input[j]


def sum_three(goal):
    """ finds three numbers in the input
      that are equal to the goal when summed.
  """

    for number in input:
        sub_goal = goal - number
        try:
            a, b = sum_two(sub_goal)
        except:
            continue
        return number, a, b

    raise Exception()


solve_1 = lambda: multiply(sum_two(2020))
solve_2 = lambda: multiply(sum_three(2020))
Beispiel #9
0
 def test_multiply0(self):
     self.assertEqual(multiply(3,5), 15)
Beispiel #10
0
 def test_numbers_3_4(self):
     self.assertEqual(multiply(3, 4), 12)
Beispiel #11
0
 def test_strings_a_3(self):
     self.assertEqual(multiply('a', 3), 'aaa')