Katex support in markdown pipeline, reveal.js

This commit is contained in:
Maciej Jur 2023-04-08 15:44:45 +02:00
parent 979462fd97
commit ffaf587c3e
11 changed files with 254 additions and 16 deletions

View file

@ -1,5 +1,16 @@
import { defineConfig } from 'astro/config';
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
// https://astro.build/config
export default defineConfig({});
export default defineConfig({
markdown: {
remarkPlugins: [
remarkMath
],
rehypePlugins: [
[rehypeKatex, {output: 'mathml'}]
]
}
});

View file

@ -13,11 +13,15 @@
"astro": "^2.2.0",
"dayjs": "^1.11.7",
"leaflet": "^1.9.3",
"leaflet.markercluster": "^1.5.3"
"leaflet.markercluster": "^1.5.3",
"rehype-katex": "^6.0.2",
"remark-math": "^5.1.1",
"reveal.js": "^4.4.0",
"sass": "^1.61.0"
},
"devDependencies": {
"@types/leaflet": "^1.9.3",
"@types/leaflet.markercluster": "^1.5.1",
"sass": "^1.61.0"
"@types/reveal.js": "^4.4.2"
}
}

View file

@ -13,6 +13,18 @@ dependencies:
leaflet.markercluster:
specifier: ^1.5.3
version: 1.5.3(leaflet@1.9.3)
rehype-katex:
specifier: ^6.0.2
version: 6.0.2
remark-math:
specifier: ^5.1.1
version: 5.1.1
reveal.js:
specifier: ^4.4.0
version: 4.4.0
sass:
specifier: ^1.61.0
version: 1.61.0
devDependencies:
'@types/leaflet':
@ -21,9 +33,9 @@ devDependencies:
'@types/leaflet.markercluster':
specifier: ^1.5.1
version: 1.5.1
sass:
specifier: ^1.61.0
version: 1.61.0
'@types/reveal.js':
specifier: ^4.4.2
version: 4.4.2
packages:
@ -686,6 +698,14 @@ packages:
resolution: {integrity: sha512-sqm9g7mHlPY/43fcSNrCYfOeX9zkTTK+euO5E6+CVijSMm5tTjkVdwdqRkY3ljjIAf8679vps5jKUoJBCLsMDA==}
dev: false
/@types/katex@0.11.1:
resolution: {integrity: sha512-DUlIj2nk0YnJdlWgsFuVKcX27MLW0KbKmGVoUHmFr+74FYYNUDAaj9ZqTADvsbE8rfxuVmSFc7KczYn5Y09ozg==}
dev: false
/@types/katex@0.16.0:
resolution: {integrity: sha512-hz+S3nV6Mym5xPbT9fnO8dDhBFQguMYpY0Ipxv06JMi1ORgnEM4M1ymWDUhUNer3ElLmT583opRo4RzxKmh9jw==}
dev: false
/@types/leaflet.markercluster@1.5.1:
resolution: {integrity: sha512-gzJzP10qO6Zkts5QNVmSAEDLYicQHTEBLT9HZpFrJiSww9eDAs5OWHvIskldf41MvDv1gbMukuEBQEawHn+wtA==}
dependencies:
@ -722,6 +742,10 @@ packages:
resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==}
dev: false
/@types/reveal.js@4.4.2:
resolution: {integrity: sha512-z+lVPEWGPFrPv3S9Mx2qLKXA4zT+Mo3GxvW68OR7lbUcCmqjn4vjaQJ2qCW+xNkBUgfR8d3fzLWHmu1PIfRiIA==}
dev: true
/@types/unist@2.0.6:
resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==}
dev: false
@ -791,6 +815,7 @@ packages:
dependencies:
normalize-path: 3.0.0
picomatch: 2.3.1
dev: false
/argparse@1.0.10:
resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
@ -886,6 +911,7 @@ packages:
/binary-extensions@2.2.0:
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
engines: {node: '>=8'}
dev: false
/bl@5.1.0:
resolution: {integrity: sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==}
@ -914,6 +940,7 @@ packages:
engines: {node: '>=8'}
dependencies:
fill-range: 7.0.1
dev: false
/browserslist@4.21.5:
resolution: {integrity: sha512-tUkiguQGW7S3IhB7N+c2MV/HZPSCPAAiYBZXLsBhFB/PCy6ZKKsZrmBayHV9fdGV/ARIfJ14NkxKzRDjvp7L6w==}
@ -1000,6 +1027,7 @@ packages:
readdirp: 3.6.0
optionalDependencies:
fsevents: 2.3.2
dev: false
/ci-info@3.8.0:
resolution: {integrity: sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==}
@ -1053,6 +1081,11 @@ packages:
resolution: {integrity: sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==}
dev: false
/commander@8.3.0:
resolution: {integrity: sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==}
engines: {node: '>= 12'}
dev: false
/common-ancestor-path@1.0.1:
resolution: {integrity: sha512-L3sHRo1pXXEqX8VU28kfgUY+YGsk09hPqZiZmLacNib6XNTCM8ubYeT7ryXQw8asB1sKgcU5lkB7ONug08aB8w==}
dev: false
@ -1273,6 +1306,7 @@ packages:
engines: {node: '>=8'}
dependencies:
to-regex-range: 5.0.1
dev: false
/find-up@4.1.0:
resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==}
@ -1302,6 +1336,7 @@ packages:
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
requiresBuild: true
dev: false
optional: true
/function-bind@1.1.1:
@ -1331,6 +1366,7 @@ packages:
engines: {node: '>= 6'}
dependencies:
is-glob: 4.0.3
dev: false
/globals@11.12.0:
resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==}
@ -1394,6 +1430,13 @@ packages:
web-namespaces: 2.0.1
dev: false
/hast-util-is-element@2.1.3:
resolution: {integrity: sha512-O1bKah6mhgEq2WtVMk+Ta5K7pPMqsBBlmzysLdcwKVrqzZQ0CHqUPiIVspNhAG1rvxpvJjtGee17XfauZYKqVA==}
dependencies:
'@types/hast': 2.3.4
'@types/unist': 2.0.6
dev: false
/hast-util-parse-selector@3.1.1:
resolution: {integrity: sha512-jdlwBjEexy1oGz0aJ2f4GKMaVKkA9jwjr4MjAAI22E5fM/TXVZHuS5OpONtdeIkRKqAaryQ2E9xNQxijoThSZA==}
dependencies:
@ -1443,6 +1486,15 @@ packages:
zwitch: 2.0.4
dev: false
/hast-util-to-text@3.1.2:
resolution: {integrity: sha512-tcllLfp23dJJ+ju5wCCZHVpzsQQ43+moJbqVX3jNWPB7z/KFC4FyZD6R7y94cHL6MQ33YtMZL8Z0aIXXI4XFTw==}
dependencies:
'@types/hast': 2.3.4
'@types/unist': 2.0.6
hast-util-is-element: 2.1.3
unist-util-find-after: 4.0.1
dev: false
/hast-util-whitespace@2.0.1:
resolution: {integrity: sha512-nAxA0v8+vXSBDt3AnRUNjyRIQ0rD+ntpbAp4LnPkumc5M9yUbSMa4XDU9Q6etY4f1Wp4bNgvc1yjiZtsTTrSng==}
dev: false
@ -1476,6 +1528,7 @@ packages:
/immutable@4.3.0:
resolution: {integrity: sha512-0AOCmOip+xgJwEVTQj1EfiDDOkPmuyllDuTuEX+DDXUgapLAsBIfkg3sxCYyCEA8mQqZrrxPUGjcOQ2JS3WLkg==}
dev: false
/import-meta-resolve@2.2.2:
resolution: {integrity: sha512-f8KcQ1D80V7RnqVm+/lirO9zkOxjGxhaTC1IPrBGd3MEfNgmNG67tSUO9gTi2F3Blr2Az6g1vocaxzkVnWl9MA==}
@ -1490,6 +1543,7 @@ packages:
engines: {node: '>=8'}
dependencies:
binary-extensions: 2.2.0
dev: false
/is-buffer@2.0.5:
resolution: {integrity: sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==}
@ -1522,6 +1576,7 @@ packages:
/is-extglob@2.1.1:
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
dev: false
/is-fullwidth-code-point@3.0.0:
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
@ -1533,6 +1588,7 @@ packages:
engines: {node: '>=0.10.0'}
dependencies:
is-extglob: 2.1.1
dev: false
/is-interactive@2.0.0:
resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==}
@ -1542,6 +1598,7 @@ packages:
/is-number@7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'}
dev: false
/is-plain-obj@4.1.0:
resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==}
@ -1601,6 +1658,20 @@ packages:
resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==}
dev: false
/katex@0.15.6:
resolution: {integrity: sha512-UpzJy4yrnqnhXvRPhjEuLA4lcPn6eRngixW7Q3TJErjg3Aw2PuLFBzTkdUb89UtumxjhHTqL3a5GDGETMSwgJA==}
hasBin: true
dependencies:
commander: 8.3.0
dev: false
/katex@0.16.4:
resolution: {integrity: sha512-WudRKUj8yyBeVDI4aYMNxhx5Vhh2PjpzQw1GRu/LVGqL4m1AxwD1GcUp0IMbdJaf5zsjtj8ghP0DOQRYhroNkw==}
hasBin: true
dependencies:
commander: 8.3.0
dev: false
/kind-of@6.0.3:
resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==}
engines: {node: '>=0.10.0'}
@ -1780,6 +1851,14 @@ packages:
- supports-color
dev: false
/mdast-util-math@2.0.2:
resolution: {integrity: sha512-8gmkKVp9v6+Tgjtq6SYx9kGPpTf6FVYRa53/DLh479aldR9AyP48qeVOgNZ5X7QUK7nOy4yw7vg6mbiGcs9jWQ==}
dependencies:
'@types/mdast': 3.0.11
longest-streak: 3.1.0
mdast-util-to-markdown: 1.5.0
dev: false
/mdast-util-phrasing@3.0.1:
resolution: {integrity: sha512-WmI1gTXUBJo4/ZmSk79Wcb2HcjPJBzM1nlI/OUWA8yk2X9ik3ffNbBGsU+09BFmXaL1IBb9fiuvq6/KMiNycSg==}
dependencies:
@ -1922,6 +2001,18 @@ packages:
micromark-util-types: 1.0.2
dev: false
/micromark-extension-math@2.1.0:
resolution: {integrity: sha512-WH+fJkveMvM3ZN+deb/jT3UW623x8xO9ycfJNDC+UQXX+V72RO6hT9KqxA7c8XFwozAFJ7tufOeG+x/CVSXHUw==}
dependencies:
'@types/katex': 0.16.0
katex: 0.16.4
micromark-factory-space: 1.0.0
micromark-util-character: 1.1.0
micromark-util-symbol: 1.0.1
micromark-util-types: 1.0.2
uvu: 0.5.6
dev: false
/micromark-factory-destination@1.0.0:
resolution: {integrity: sha512-eUBA7Rs1/xtTVun9TmV3gjfPz2wEwgK5R5xcbIM5ZYAtvGF6JkyaDsj0agx8urXnO31tEO6Ug83iVH3tdedLnw==}
dependencies:
@ -2129,6 +2220,7 @@ packages:
/normalize-path@3.0.0:
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
engines: {node: '>=0.10.0'}
dev: false
/npm-run-path@5.1.0:
resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==}
@ -2250,6 +2342,7 @@ packages:
/picomatch@2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
dev: false
/pify@4.0.1:
resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
@ -2333,6 +2426,20 @@ packages:
engines: {node: '>=8.10.0'}
dependencies:
picomatch: 2.3.1
dev: false
/rehype-katex@6.0.2:
resolution: {integrity: sha512-C4gDAlS1+l0hJqctyiU64f9CvT00S03qV1T6HiMzbSuLBgWUtcqydWHY9OpKrm0SpkK16FNd62CDKyWLwV2ppg==}
dependencies:
'@types/hast': 2.3.4
'@types/katex': 0.11.1
hast-util-to-text: 3.1.2
katex: 0.15.6
rehype-parse: 8.0.4
unified: 10.1.2
unist-util-remove-position: 4.0.2
unist-util-visit: 4.1.2
dev: false
/rehype-parse@8.0.4:
resolution: {integrity: sha512-MJJKONunHjoTh4kc3dsM1v3C9kGrrxvA3U8PxZlP2SjH8RNUSrb+lF7Y0KVaUDnGH2QZ5vAn7ulkiajM9ifuqg==}
@ -2379,6 +2486,15 @@ packages:
- supports-color
dev: false
/remark-math@5.1.1:
resolution: {integrity: sha512-cE5T2R/xLVtfFI4cCePtiRn+e6jKMtFDR3P8V3qpv8wpKjwvHoBA4eJzvX+nVrnlNy0911bdGmuspCSwetfYHw==}
dependencies:
'@types/mdast': 3.0.11
mdast-util-math: 2.0.2
micromark-extension-math: 2.1.0
unified: 10.1.2
dev: false
/remark-parse@10.0.1:
resolution: {integrity: sha512-1fUyHr2jLsVOkhbvPRBJ5zTKZZyD6yZzYaWCS6BPBdQ8vEMBCH+9zNCDA6tET/zHCi/jLqjCWtlJZUPk+DbnFw==}
dependencies:
@ -2464,6 +2580,11 @@ packages:
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
dev: false
/reveal.js@4.4.0:
resolution: {integrity: sha512-jIV6C9V2NEUjGzU8L6dUFGpk1KJmq7/EzP2fOW67ggc2c0Cp/PdprWxZ9Qgp46F0T2ZWDCjQ1p3Ytzy5jA6a2w==}
engines: {node: '>=10.0.0'}
dev: false
/rollup@3.20.2:
resolution: {integrity: sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==}
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
@ -2507,6 +2628,7 @@ packages:
chokidar: 3.5.3
immutable: 4.3.0
source-map-js: 1.0.2
dev: false
/section-matter@1.0.0:
resolution: {integrity: sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==}
@ -2569,6 +2691,7 @@ packages:
/source-map-js@1.0.2:
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}
dev: false
/source-map@0.7.4:
resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==}
@ -2716,6 +2839,7 @@ packages:
engines: {node: '>=8.0'}
dependencies:
is-number: 7.0.0
dev: false
/trim-lines@3.0.1:
resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==}
@ -2786,6 +2910,13 @@ packages:
vfile: 5.3.7
dev: false
/unist-util-find-after@4.0.1:
resolution: {integrity: sha512-QO/PuPMm2ERxC6vFXEPtmAutOopy5PknD+Oq64gGwxKtk4xwo9Z97t9Av1obPmGU0IyTa6EKYUfTrK2QJS3Ozw==}
dependencies:
'@types/unist': 2.0.6
unist-util-is: 5.2.1
dev: false
/unist-util-generated@2.0.1:
resolution: {integrity: sha512-qF72kLmPxAw0oN2fwpWIqbXAVyEqUzDHMsbtPvOudIlUzXYFIeQIuxXQCRCFh22B7cixvU0MG7m3MW8FTq/S+A==}
dev: false
@ -2809,6 +2940,13 @@ packages:
'@types/unist': 2.0.6
dev: false
/unist-util-remove-position@4.0.2:
resolution: {integrity: sha512-TkBb0HABNmxzAcfLf4qsIbFbaPDvMO6wa3b3j4VcEzFVaw1LBKwnW4/sRJ/atSLSzoIg41JWEdnE7N6DIhGDGQ==}
dependencies:
'@types/unist': 2.0.6
unist-util-visit: 4.1.2
dev: false
/unist-util-stringify-position@3.0.3:
resolution: {integrity: sha512-k5GzIBZ/QatR8N5X2y+drfpWG8IDBzdnVj6OInRNWm1oXrzydiaAT2OQiA8DPRRZyAKb9b6I2a6PxYklZD0gKg==}
dependencies:

View file

@ -40,7 +40,9 @@ def solve1() -> int:
The score is calculated by taking a dot product of the matrix with the negation of the mask (which eliminates unmarked numbers), summing the remaining values and multiplying by the value of the drawn number.
$$ \text{score} = v_{drawn} \cdot \sum_{i=1}^{n} \sum_{j=1}^{m} \text{board}[i,j] \cdot \neg \text{mask}[i,j] $$
$$
\text{score} = v_{drawn} \cdot \sum_{i=1}^{n} \sum_{j=1}^{m} \text{board}[i,j] \cdot \neg \text{mask}[i,j]
$$
## Task 2
This is analogous to the first task, but we need to find the last winning board. I iterate from the end of the vector. The inner loop is similar to the one in the first task, just needed to find when the first board doesn't match and then calculate another mask for the round afterwards (scale+1).

View file

@ -17,13 +17,19 @@ def load() -> list[int]:
## Task 1
In this task the way to calculate the fuel expenditure is to sum up the fuel expenditure to all other points. The way it's calculated is linear. Formula for fuel expenditure, where C is the set of all points and x is the point we want to calculate the fuel expenditure for:
$$\sum_{c \in C} |x - c|$$
$$
\sum_{c \in C} |x - c|
$$
We are looking for the point with minimal fuel expenditure:
$$\min_{x} \sum_{c \in C} |x - c|$$
$$
\min_{x} \sum_{c \in C} |x - c|
$$
The way to find the optimal point is to find the median of all the points where crabs are placed, because the median happens to be the point where the fuel expenditure is minimal. Formula for the median:
$$\frac{1}{2} \sum_{c \in C} c$$
$$
\frac{1}{2} \sum_{c \in C} c
$$
I don't really know how this works myself, but the proof for why it works can be found [here](https://math.stackexchange.com/questions/113270/the-median-minimizes-the-sum-of-absolute-deviations-the-ell-1-norm).
@ -40,7 +46,9 @@ In this task we have to find the optimal point for all crabs to move to on a sin
The way I solved this is I looked up the formula for the function that calculates the value for the n-th element in the sequence on the Internet. It happens to be:
$$ f(n) = \frac{n * (n + 1)}{2} $$
$$
f(n) = \frac{n * (n + 1)}{2}
$$
I implemented this formula in the code below:
```python
@ -49,15 +57,21 @@ def nth_sum(n: int) -> int:
```
In the solution to the task 2 I used NumPy to create a matrix of the form:
$$ \begin{bmatrix} 0 & 0 & 0 & \cdots & 0 \\\\ 1 & 1 & 1 & \cdots & 1 \\\\ 2 & 2 & 2 & \cdots & 2 \\\\ \vdots & \vdots & \vdots & \ddots & \vdots \\\\ n & n & n & \cdots & n \end{bmatrix} $$
$$
\begin{bmatrix} 0 & 0 & 0 & \cdots & 0 \\\\ 1 & 1 & 1 & \cdots & 1 \\\\ 2 & 2 & 2 & \cdots & 2 \\\\ \vdots & \vdots & \vdots & \ddots & \vdots \\\\ n & n & n & \cdots & n \end{bmatrix}
$$
Then I subtracted the vector of the crab positions from the matrix. The result is a matrix with the distances from the crab to all other possible points.
$$ \begin{bmatrix} |0 - c_1| & |0 - c_2| & |0 - c_3| & \cdots & |0 - c_i| \\\\ |1 - c_1| & |1 - c_2| & |1 - c_3| & \cdots & |1 - c_i| \\\\ |2 - c_1| & |2 - c_2| & |2 - c_3| & \cdots & |2 - c_i| \\\\ \vdots & \vdots & \vdots & \ddots & \vdots \\\\ |n - c_1| & |n - c_2| & |n - c_3| & \cdots & |n - c_i| \end{bmatrix} $$
$$
\begin{bmatrix} |0 - c_1| & |0 - c_2| & |0 - c_3| & \cdots & |0 - c_i| \\\\ |1 - c_1| & |1 - c_2| & |1 - c_3| & \cdots & |1 - c_i| \\\\ |2 - c_1| & |2 - c_2| & |2 - c_3| & \cdots & |2 - c_i| \\\\ \vdots & \vdots & \vdots & \ddots & \vdots \\\\ |n - c_1| & |n - c_2| & |n - c_3| & \cdots & |n - c_i| \end{bmatrix}
$$
We then apply the formula for the n-th element in the sequence to the matrix. The result is a matrix with the fuel expenditure to all other points. When we sum the values in rows of the matrix we get the total fuel expenditure to all points for the crabs.
$$ \min \sum_{c \in C} f(|x - c|) $$
$$
\min \sum_{c \in C} f(|x - c|)
$$
By finding the row with the minimal fuel expenditure we can find the optimal point. Below is the implementation in NumPy:
```python

View file

@ -60,7 +60,9 @@ def step(input: np.ndarray):
```
I used a convolution matrix of the following shape:
$$ \begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 1 \end{bmatrix} $$
$$
\begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 0 & 1 \\\\ 1 & 1 & 1 \end{bmatrix}
$$
## Task 1
Here we sum all the flashes that happened in all of the iterations with `np.sum`:

View file

@ -11,4 +11,10 @@ export const collections = {
math: z.boolean().optional()
})
}),
slides: defineCollection({
schema: z.object({
title: z.string(),
date: z.date(),
})
})
}

View file

@ -0,0 +1,14 @@
---
title: "HELLO"
date: 2019-12-12
---
## HEllo!
fjdshfhdskf
---
dsad
$$a + b = 10$$

View file

@ -2,7 +2,6 @@
import Article from '../../layouts/Article.astro';
import { getCollection } from 'astro:content';
export async function getStaticPaths () {
return (await getCollection('aoc'))
.map(entry => ({params: {slug: entry.slug}, props: {entry}}));

View file

@ -0,0 +1,32 @@
---
import 'reveal.js/dist/reveal.css';
import 'reveal.js/dist/theme/white.css';
import Base from '../../layouts/Base.astro';
import { getCollection } from 'astro:content';
export async function getStaticPaths () {
return (await getCollection('slides'))
.map(entry => ({params: {slug: entry.slug}, props: {entry}}));
}
const { entry } = Astro.props;
---
<Base>
<div class="reveal">
<div class="slides">
<section data-markdown>
<textarea data-template>{entry.body}</textarea>
</section>
</div>
</div>
<script>
import Reveal from 'reveal.js';
import Markdown from 'reveal.js/plugin/markdown/markdown';
Reveal.initialize({
plugins: [ Markdown ]
});
</script>
</Base>

View file

@ -0,0 +1,16 @@
---
import dayjs from 'dayjs';
import List from '../../layouts/List.astro';
import { getCollection } from 'astro:content';
const content = await getCollection('slides');
const pages = content
.map(entry => ({
title: entry.data.title,
slug: entry.slug,
date: dayjs(entry.data.date),
}));
---
<List title="Slides" pages={pages} />