75 lines
2.0 KiB
Plaintext
75 lines
2.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "42c30745",
|
|
"metadata": {},
|
|
"source": [
|
|
"# [Champernowne's Constant](https://projecteuler.net/problem=40)\n",
|
|
"\n",
|
|
"This is certainly not the fastest or most clever solution for calculating digits of [Champernowne's constant](https://en.wikipedia.org/wiki/Champernowne_constant), but it's fast enough, and pretty comprehensible.\n",
|
|
"\n",
|
|
"Since there are so many strings to concatenate, for performance it is helpful to use the [`str.join` method](https://docs.python.org/3/library/stdtypes.html#str.join)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "deed40a4",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"210"
|
|
]
|
|
},
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from itertools import count\n",
|
|
"\n",
|
|
"c = '.' + ''.join(str(k) for k in range(1, 1_000_001))\n",
|
|
"prod(int(c[i]) for i in (1, 10, 100, 1000, 10000, 100000, 1000000))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "59074921",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Relevant sequences\n",
|
|
"* Digits of Champernowne's constant: [A033307](https://oeis.org/A033307)\n",
|
|
"\n",
|
|
"#### Copyright (C) 2025 filifa\n",
|
|
"\n",
|
|
"This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)."
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|