diff --git a/notebooks/problem0076.ipynb b/notebooks/problem0076.ipynb new file mode 100644 index 0000000..5c5bc54 --- /dev/null +++ b/notebooks/problem0076.ipynb @@ -0,0 +1,98 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "c09827d4", + "metadata": {}, + "source": [ + "# [Counting Summations](https://projecteuler.net/problem=76)\n", + "\n", + "We want $p(100) - 1$, where $p(n)$ is the [partition function](https://en.wikipedia.org/wiki/Partition_function_(number_theory)). We subtract 1 because $p(n)$ counts $n$ by itself as a partition of $n$, but we only want partitions composed of two or more numbers.\n", + "\n", + "Guess what? SageMath has this built-in." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "1e4ff844", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "190569291" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "number_of_partitions(100) - 1" + ] + }, + { + "cell_type": "markdown", + "id": "d06d7ff2", + "metadata": {}, + "source": [ + "Alternatively, we can adapt any of our approaches to [problem 31](https://projecteuler.net/problem=31), where we construct the generating function. Here's the last approach from that problem." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "bba7ef34", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "190569291" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "R. = PowerSeriesRing(ZZ, default_prec=101)\n", + "G = 1 / prod(1 - x^n for n in range(1, 100))\n", + "G[100]" + ] + }, + { + "cell_type": "markdown", + "id": "681d7716", + "metadata": {}, + "source": [ + "## Relevant sequences\n", + "* Partition numbers: [A000041](https://oeis.org/A000041)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SageMath 9.5", + "language": "sage", + "name": "sagemath" + }, + "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.11.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}