home

Scientific Computing (Psychology 9040a)

Fall, 2020

Assignment 4

Due: Oct 20 by 11:55 pm (London ON time)


Advent of Code 2015 Day 2

Complete both Part 1 and Part 2 of Advent of Code 2015 Day 2.

Please make sure to save your puzzle input as a file called A4_input.txt

Your code should assume that the input is in a file named A4_input.txt

This will allow us to run your code locally to veryify that it works.

Hint: In Part 1 and in Part 2 you will need to find the smallest of three quantities. You can use the built-in function min() to do this:

# in Part 1:
slack = min(l*w,l*h,w*h)

# in Part 2:
ribbon = 2*min(l+w,l+h,w+h)

Hint: To load in the input file line by line there are many ways to do it, but here is one way:

with open("A4_input.txt") as fp:
    for line in fp:
        l,w,h = map(int,line.split('x'))

Here is another way that will use the NumPy function genfromtxt() to load in the entire file into one big 2D array:

import numpy as np
a4 = np.genfromtxt('A4_input.txt', delimiter='x')

There are other ways to read in the file as well. Whatever works for you is fine.