{ "cells": [ { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "def wrapping_paper_area(l, w, h):\n", " side_area = [l*w, w*h, h*l]\n", " surface_area = 2 * sum(side_area)\n", " slack = min(side_area)\n", " return surface_area + slack\n", "\n", "def total_wrapping_paper_area(iter):\n", " return sum((wrapping_paper_area(*l) for l in iter))\n", "\n", "def string_to_list(s):\n", " return (map(int, l.split('x')) \n", " for l in s.splitlines())\n", "\n", "def ribbon_length(l, w, h):\n", " if l >= w and l >= h:\n", " smaller_dimensions = (w, h)\n", " \n", " if w >= l and w >= h:\n", " smaller_dimensions = (l, h)\n", " \n", " if h >= l and h >= w:\n", " smaller_dimensions = (l, w)\n", " \n", " return 2*sum(smaller_dimensions) + l*w*h\n", "\n", "def total_ribbon_length(iter):\n", " return sum((ribbon_length(*l) for l in iter))" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [], "source": [ "assert wrapping_paper_area(2, 3, 4) == 58\n", "assert wrapping_paper_area(1, 1, 10) == 43" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "import import_ipynb\n", "import helper\n", "s = helper.read_file('2015_2.txt')" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1586300" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "total_wrapping_paper_area(string_to_list(s))" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "assert ribbon_length(2, 3, 4) == 34\n", "assert ribbon_length(1, 1, 10) == 14" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3737498" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "total_ribbon_length(string_to_list(s))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" }, "title": "I Was Told There Would Be No Math" }, "nbformat": 4, "nbformat_minor": 2 }