diff --git a/APL/2021/01.apl b/APL/2021/01.apl new file mode 100644 index 0000000..7474f31 --- /dev/null +++ b/APL/2021/01.apl @@ -0,0 +1,3 @@ +input ← ⍎¨⊃⎕NGET'../.cache/2021/1' 1 +⎕ ← +/21266\n", - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/21217\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/21648020\n", - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "×/⊃{d h←⍵⋄(d+((2⊃⍺)×'d'≡⊃⊃⍺)-((2⊃⍺)×'u'≡⊃⊃⍺)) (h+((2⊃⍺)×'f'≡⊃⊃⍺))}/⌽(⊂(0 0)),data" - ] - }, - { - "cell_type": "markdown", - "id": "2005d257-213a-4b78-82cc-86b9a8808191", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "1b08b311-2eb8-48ee-b0c5-d2e0e85ac66d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "1759818555\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "×/1↓⊃{a h d←⍵⋄(a+((2⊃⍺)×'d'≡⊃⊃⍺)-((2⊃⍺)×'u'≡⊃⊃⍺)) (h+((2⊃⍺)×'f'≡⊃⊃⍺)) (d+((a×2⊃⍺)×'f'≡⊃⊃⍺))}/⌽(⊂(0 0 0)),data" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/APL/2021/03.apl b/APL/2021/03.apl new file mode 100644 index 0000000..ae9f57d --- /dev/null +++ b/APL/2021/03.apl @@ -0,0 +1,3 @@ +input ← ⊃⎕NGET '../.cache/2021/3' 1 +⎕ ← ×/⊃{⍺+2×⍵}/⌽(⊢,~)∘{(≢⍵)≤2×+/⍎¨⍵}¨↓⍉↑ input +⎕ ← ×/{2⊥⍎¨⍵}¨{x←⍵⋄⊃⊃{i←⍺⋄m←{(x+1)⊃⍵,~⍵}{(≢⍵)≤2×+/⍎¨⍵}i⊃↓⍉↑⍵⋄o←({m=⍎i⊃⍵}¨⍵)/⍵⋄(1+0=≢o)⊃o ⍵}/⌽(⊂input),⍳≢⊃input}¨0 1 diff --git a/APL/2021/03.ipynb b/APL/2021/03.ipynb deleted file mode 100644 index d64ab70..0000000 --- a/APL/2021/03.ipynb +++ /dev/null @@ -1,88 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "99f6e7d7-c153-4f43-a953-e6f2e0a8fccd", - "metadata": {}, - "outputs": [], - "source": [ - "data ← ⊃⎕NGET '03.txt' 1" - ] - }, - { - "cell_type": "markdown", - "id": "f1a4ef9e-2a1a-429c-ba13-1f5041415d6d", - "metadata": {}, - "source": [ - "### Part 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "d4e3e1a9-00a2-42ce-8335-c462aa69a3dd", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "3895776\n", - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "×/⊃{⍺+2×⍵}/⌽(⊢,~)∘{(≢⍵)≤2×+/⍎¨⍵}¨↓⍉↑data" - ] - }, - { - "cell_type": "markdown", - "id": "2692e4a0-785e-4c39-b114-e8cf673daeab", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "06ccee11-257a-4e05-9313-a07e46b753cf", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "7928162\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "×/{2⊥⍎¨⍵}¨{x←⍵⋄⊃⊃{i←⍺⋄m←{(x+1)⊃⍵,~⍵}{(≢⍵)≤2×+/⍎¨⍵}i⊃↓⍉↑⍵⋄o←({m=⍎i⊃⍵}¨⍵)/⍵⋄(1+0=≢o)⊃o ⍵}/⌽(⊂data),⍳≢⊃data}¨0 1" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/APL/2021/04.apl b/APL/2021/04.apl new file mode 100644 index 0000000..27dacac --- /dev/null +++ b/APL/2021/04.apl @@ -0,0 +1,5 @@ +input ← ⊃⎕NGET '../.cache/2021/4' 1 +nums ← ⍎¨','(≠⊆⊢)⊃input +boards ← {{⍎¨' '(≠⊆⊢)⍵}¨¨({0≠≢⍵}¨⍵)⊆⍵}2↓input +⎕ ← {i b←⍵⋄w←{({∨/(∧/¯1=⊢)¨⍵,↓⍉↑⍵}¨⍵)/⍵}b⋄0<≢w:((i-1)⊃nums)×+/(∊⊃w)~¯1⋄∇(1+i)({⍵=(i⊃nums):¯1⋄⍵}¨¨¨b)}1 boards +⎕ ← {i b←⍵⋄w←{({∨/(∧/¯1=⊢)¨⍵,↓⍉↑⍵}¨⍵)/⍵}b⋄(0<≢w)∧1=≢b:((i-1)⊃nums)×+/(∊⊃w)~¯1⋄∇(1+i)({⍵=(i⊃nums):¯1⋄⍵}¨¨¨b~w)}1 boards diff --git a/APL/2021/04.ipynb b/APL/2021/04.ipynb deleted file mode 100644 index 3143e21..0000000 --- a/APL/2021/04.ipynb +++ /dev/null @@ -1,90 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "a7062017-1cc1-4888-822f-236fc2cb4780", - "metadata": {}, - "outputs": [], - "source": [ - "data ← ⊃⎕NGET '04.txt' 1\n", - "nums ← ⍎¨','(≠⊆⊢)⊃data\n", - "boards ← {{⍎¨' '(≠⊆⊢)⍵}¨¨({0≠≢⍵}¨⍵)⊆⍵}2↓data" - ] - }, - { - "cell_type": "markdown", - "id": "bee465ae-0500-4fcd-8104-ed654a39f8f6", - "metadata": {}, - "source": [ - "### Part 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "ad828024-cc75-459c-aeb5-eef32282c9f8", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "49860\n", - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{i b←⍵⋄w←{({∨/(∧/¯1=⊢)¨⍵,↓⍉↑⍵}¨⍵)/⍵}b⋄0<≢w:((i-1)⊃nums)×+/(∊⊃w)~¯1⋄∇(1+i)({⍵=(i⊃nums):¯1⋄⍵}¨¨¨b)}1 boards" - ] - }, - { - "cell_type": "markdown", - "id": "a973e8ae-9fdb-4e38-b6f7-cb7d78a62c48", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "f66d1533-a6f6-4198-a2f0-e7f9cbf51257", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "24628\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{i b←⍵⋄w←{({∨/(∧/¯1=⊢)¨⍵,↓⍉↑⍵}¨⍵)/⍵}b⋄(0<≢w)∧1=≢b:((i-1)⊃nums)×+/(∊⊃w)~¯1⋄∇(1+i)({⍵=(i⊃nums):¯1⋄⍵}¨¨¨b~w)}1 boards" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/APL/2021/05.apl b/APL/2021/05.apl new file mode 100644 index 0000000..f2b689d --- /dev/null +++ b/APL/2021/05.apl @@ -0,0 +1,4 @@ +input ← ((⍎¨','(≠⊆⊢)⊢)¨(⊂'->')~⍨' '(≠⊆⊢)⊢)¨⊃⎕NGET '../.cache/2021/5' 1 +iter ← {a b←⍵⋄a≡b:⊂b⋄(⊂a),∇(a+×b-a) b} +⎕ ← +/2≤≢¨⊢/{⍺ ⍵}⌸⊃,/iter¨{(∨⌿⍉↑=⌿⍉↑⍵)/⍵} input +⎕ ← +/2≤≢¨⊢/{⍺ ⍵}⌸⊃,/iter¨ input diff --git a/APL/2021/05.ipynb b/APL/2021/05.ipynb deleted file mode 100644 index 8d8753f..0000000 --- a/APL/2021/05.ipynb +++ /dev/null @@ -1,98 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "a7062017-1cc1-4888-822f-236fc2cb4780", - "metadata": {}, - "outputs": [], - "source": [ - "data ← ((⍎¨','(≠⊆⊢)⊢)¨(⊂'->')~⍨' '(≠⊆⊢)⊢)¨⊃⎕NGET '05.txt' 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "b23a78e7-12ef-4f68-b44e-666926097f07", - "metadata": {}, - "outputs": [], - "source": [ - "iter ← {a b←⍵⋄a≡b:⊂b⋄(⊂a),∇(a+×b-a) b}" - ] - }, - { - "cell_type": "markdown", - "id": "bee465ae-0500-4fcd-8104-ed654a39f8f6", - "metadata": {}, - "source": [ - "### Part 1" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "dd1b3c61-9480-4e03-b5a5-e116f50a7b6d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "5698\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/2≤≢¨⊢/{⍺ ⍵}⌸⊃,/iter¨{(∨⌿⍉↑=⌿⍉↑⍵)/⍵}data" - ] - }, - { - "cell_type": "markdown", - "id": "a973e8ae-9fdb-4e38-b6f7-cb7d78a62c48", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "7691c6f8-f313-470d-971b-3a506053e6df", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "15463\n", - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/2≤≢¨⊢/{⍺ ⍵}⌸⊃,/iter¨data" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/APL/2021/06.apl b/APL/2021/06.apl new file mode 100644 index 0000000..75ba58d --- /dev/null +++ b/APL/2021/06.apl @@ -0,0 +1,5 @@ +input ← ⍎¨','(≠⊆⊢)⊃⊃⎕NGET '../.cache/2021/6' 1 +⎕PP←32 +solve ← {+/({((⊃⍵+⊢)@7)1⌽⍵}⍣⍵) ⊢⌿⍉{⍺,1-⍨≢⍵}⌸input,⍨1-⍨⍳9} +⎕ ← solve 80 +⎕ ← solve 256 diff --git a/APL/2021/06.ipynb b/APL/2021/06.ipynb deleted file mode 100644 index 6c119bd..0000000 --- a/APL/2021/06.ipynb +++ /dev/null @@ -1,99 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "3e1eb3d0-7a65-403c-8816-0b914a1f705b", - "metadata": {}, - "outputs": [], - "source": [ - "data ← ⍎¨','(≠⊆⊢)⊃⊃⎕NGET '06.txt' 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "bac640c9-2cb2-4861-9fb9-2aba12138d3f", - "metadata": {}, - "outputs": [], - "source": [ - "⎕PP←32\n", - "solve ← {+/({((⊃⍵+⊢)@7)1⌽⍵}⍣⍵) ⊢⌿⍉{⍺,1-⍨≢⍵}⌸data,⍨1-⍨⍳9}" - ] - }, - { - "cell_type": "markdown", - "id": "8213c71c-7fbb-41ba-9f01-ab7cf8da9bf5", - "metadata": {}, - "source": [ - "### Part 1" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "fdb19c65-0147-4656-b698-8322bc292cbd", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "345793\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve 80" - ] - }, - { - "cell_type": "markdown", - "id": "db5f241e-7218-4b8a-a881-cc265b619467", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "585dfd8f-1de6-4b6d-888c-579ea35ece24", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "1572643095893\n", - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve 256" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/APL/2021/07.apl b/APL/2021/07.apl new file mode 100644 index 0000000..2441dda --- /dev/null +++ b/APL/2021/07.apl @@ -0,0 +1,3 @@ +input ← ⍎¨','(≠⊆⊢)⊃⊃⎕NGET '../.cache/2021/7' 1 +⎕ ← ⌊/{+/|¨⍵-input}¨⍳≢input +⎕ ← ⌊/{+/(+/⍳)¨|¨⍵-input}¨⍳≢input diff --git a/APL/2021/07.ipynb b/APL/2021/07.ipynb deleted file mode 100644 index 526e0e0..0000000 --- a/APL/2021/07.ipynb +++ /dev/null @@ -1,88 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": {}, - "outputs": [], - "source": [ - "data ← ⍎¨','(≠⊆⊢)⊃⊃⎕NGET '07.txt' 1" - ] - }, - { - "cell_type": "markdown", - "id": "2a377103-6ac1-4513-8e60-aabeac51e1eb", - "metadata": {}, - "source": [ - "### Part 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "4dd03668-cffc-4d2a-8c5f-9af763d7a9ed", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "340052\n", - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "⌊/{+/|¨⍵-data}¨⍳≢data" - ] - }, - { - "cell_type": "markdown", - "id": "ba873ee7-88c1-48cd-8563-dc48832ad154", - "metadata": {}, - "source": [ - "### Part 2" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "39f4060b-fae9-4043-aaf3-fe9b9794716b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "92948968\n", - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "⌊/{+/(+/⍳)¨|¨⍵-data}¨⍳≢data" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/08.apl b/APL/2021/08.apl new file mode 100644 index 0000000..8660d80 --- /dev/null +++ b/APL/2021/08.apl @@ -0,0 +1,4 @@ +input ← (((10⍴1),0,(4⍴1))⊆⊢)¨' '(≠⊆⊢)¨⊃⎕NGET '../.cache/2021/8' 1 +mat ← ⍎¨10 3⍴'632222521532442531631322742642' +⎕ ← +/((2 3 4 7)∊⍨⊢)¨∊≢¨¨⊃↓⍉⌽↑input +⎕ ← +/{a b←⍵⋄l←{⊃(⍵=≢¨a)/a}¨4 2⋄10⊥{1-⍨mat⍳(≢⍵)(≢⍵∩⊃l)(≢⍵∩2⊃l)}¨b}¨input diff --git a/APL/2021/08.ipynb b/APL/2021/08.ipynb deleted file mode 100644 index e93772e..0000000 --- a/APL/2021/08.ipynb +++ /dev/null @@ -1,103 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← (((10⍴1),0,(4⍴1))⊆⊢)¨' '(≠⊆⊢)¨⊃⎕NGET '08.txt' 1" - ] - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [ - { - "data": { - "text/html": "392\n" - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/((2 3 4 7)∊⍨⊢)¨∊≢¨¨⊃↓⍉⌽↑data" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "1004688\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mat←⍎¨10 3⍴'632222521532442531631322742642'\n", - "+/{a b←⍵⋄l←{⊃(⍵=≢¨a)/a}¨4 2⋄10⊥{1-⍨mat⍳(≢⍵)(≢⍵∩⊃l)(≢⍵∩2⊃l)}¨b}¨data" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/09.apl b/APL/2021/09.apl new file mode 100644 index 0000000..1f25966 --- /dev/null +++ b/APL/2021/09.apl @@ -0,0 +1,5 @@ +input ← ↑⍎¨¨⊃⎕NGET '../.cache/2021/9' 1 +low←{w←⍵⋄⊃∧/{w<⍵}¨(⍉9,⍉¯1↓⍵)(⍉9,⍨⍉1↓⍵)(9,⍉¯1↓⍉⍵)(9,⍨⍉1↓⍉⍵)}input +⎕ ← +/∊low×input+1 +dfs ← {x v←⍵⋄(⊂x)∊v:v⋄⊃{~(⊂⍺)∊⍳⍴input:⍵⋄⍺⌷input≥9:⍵⋄dfs ⍺ ⍵}/(((x+⊢)¨(¯1 0)(1 0)(0 1)(0 ¯1)),⊂(v∪⊂x))} +⎕ ← ×/3↑{⍵[⍒⍵]}{≢dfs ⍵ (⍳0)}¨⍸low diff --git a/APL/2021/09.ipynb b/APL/2021/09.ipynb deleted file mode 100644 index 22315a3..0000000 --- a/APL/2021/09.ipynb +++ /dev/null @@ -1,104 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ↑⍎¨¨⊃⎕NGET '09.txt' 1" - ] - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [ - { - "data": { - "text/html": "425\n" - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "low←{w←⍵⋄⊃∧/{w<⍵}¨(⍉9,⍉¯1↓⍵)(⍉9,⍨⍉1↓⍵)(9,⍉¯1↓⍉⍵)(9,⍨⍉1↓⍉⍵)}data\n", - "+/∊low×data+1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "1135260\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dfs ← {x v←⍵⋄(⊂x)∊v:v⋄⊃{~(⊂⍺)∊⍳⍴data:⍵⋄⍺⌷data≥9:⍵⋄dfs ⍺ ⍵}/(((x+⊢)¨(¯1 0)(1 0)(0 1)(0 ¯1)),⊂(v∪⊂x))}\n", - "×/3↑{⍵[⍒⍵]}{≢dfs ⍵ (⍳0)}¨⍸low" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/10.apl b/APL/2021/10.apl new file mode 100644 index 0000000..df607e0 --- /dev/null +++ b/APL/2021/10.apl @@ -0,0 +1,4 @@ +input ← ⊃⎕NGET '../.cache/2021/10' 1 +⎕PP ← 32 +⎕ ← +/{{l s←⍵⋄0=≢l:0⋄(⊃l)∊'([{<':∇(1↓l)(s,⍨⊃l)⋄(⊂(⊃s),⊃l)∊('()' '[]' '{}' '<>'):∇(1↓l)(1↓s)⋄⊃(')]}>'=⊃l)/(3 57 1197 25137)}⍵ ''}¨ input +⎕ ← {⍵[⍋⍵][⌈2÷⍨≢⍵]}{(⍵≠¯1)/⍵}{{l s←⍵⋄0=≢l:{⍺+5×⍵}/{⊃⍸'([{<'=⊃⍵}¨⌽s⋄(⊃l)∊'([{<':∇(1↓l)(s,⍨⊃l)⋄(⊂(⊃s),⊃l)∊('()' '[]' '{}' '<>'):∇(1↓l)(1↓s)⋄¯1}⍵ ''}¨ input diff --git a/APL/2021/10.ipynb b/APL/2021/10.ipynb deleted file mode 100644 index 33baf55..0000000 --- a/APL/2021/10.ipynb +++ /dev/null @@ -1,103 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ⊃⎕NGET '10.txt' 1\n", - "⎕PP ← 32" - ] - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [ - { - "data": { - "text/html": "278475\n" - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/{{l s←⍵⋄0=≢l:0⋄(⊃l)∊'([{<':∇(1↓l)(s,⍨⊃l)⋄(⊂(⊃s),⊃l)∊('()' '[]' '{}' '<>'):∇(1↓l)(1↓s)⋄⊃(')]}>'=⊃l)/(3 57 1197 25137)}⍵ ''}¨data" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "3015539998\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{⍵[⍋⍵][⌈2÷⍨≢⍵]}{(⍵≠¯1)/⍵}{{l s←⍵⋄0=≢l:{⍺+5×⍵}/{⊃⍸'([{<'=⊃⍵}¨⌽s⋄(⊃l)∊'([{<':∇(1↓l)(s,⍨⊃l)⋄(⊂(⊃s),⊃l)∊('()' '[]' '{}' '<>'):∇(1↓l)(1↓s)⋄¯1}⍵ ''}¨data" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/11.apl b/APL/2021/11.apl new file mode 100644 index 0000000..85f0a68 --- /dev/null +++ b/APL/2021/11.apl @@ -0,0 +1,9 @@ +input ← ⍎¨¨⊃⎕NGET '../.cache/2021/11' 1 +up←{⍉0,⍨⍉1↓⍵} +down←{⍉0,⍉¯1↓⍵} +left←{0,⍨⍉1↓⍉⍵} +right←{0,⍉¯1↓⍉⍵} +ff←{10≠⍵}×{10⌊⍵+(⍵>0)∧(⊢+left+right)(⊢+up+down)10=⍵} +step←{{a b←⍵⋄a≡b:a⋄∇(ff a)a}1+⍵ 0} +⎕ ← {d n←⍵⋄n>100:0⋄(⊂+/0=∊d)+∇(step d)(n+1)}(↑input) 0 +⎕ ← {d n←⍵⋄~∨/∊d:n⋄∇(step d)(n+1)}(↑input) 0 diff --git a/APL/2021/11.ipynb b/APL/2021/11.ipynb deleted file mode 100644 index c50f647..0000000 --- a/APL/2021/11.ipynb +++ /dev/null @@ -1,121 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ⍎¨¨⊃⎕NGET '11.txt' 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "up←{⍉0,⍨⍉1↓⍵}\n", - "down←{⍉0,⍉¯1↓⍵}\n", - "left←{0,⍨⍉1↓⍉⍵}\n", - "right←{0,⍉¯1↓⍉⍵}\n", - "ff←{10≠⍵}×{10⌊⍵+(⍵>0)∧(⊢+left+right)(⊢+up+down)10=⍵}\n", - "step←{{a b←⍵⋄a≡b:a⋄∇(ff a)a}1+⍵ 0}" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "1659\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{d n←⍵⋄n>100:0⋄(⊂+/0=∊d)+∇(step d)(n+1)}(↑data) 0" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "227\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{d n←⍵⋄~∨/∊d:n⋄∇(step d)(n+1)}(↑data) 0" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/12.apl b/APL/2021/12.apl new file mode 100644 index 0000000..433617e --- /dev/null +++ b/APL/2021/12.apl @@ -0,0 +1,5 @@ +input ← '-'(≠⊆⊢)¨⊃⎕NGET '../.cache/2021/12' 1 +next ← {w←⍵⋄⊃{a b←⍺⋄a≡w:⍵,⊂b⋄b≡w:⍵,⊂a⋄⍵}/input,⊂⍬} +search ← {p v s←⍵⋄p≡'end':1⋄t←(∧/97≤⎕UCS p)∧∨/(p≡⊢)¨v⋄t∧s∨p≡'start':0⋄+/{search ⍵ (v∪⊂p) (t∨s)}¨next p} +⎕ ← search 'start' ⍬ 1 +⎕ ← search 'start' ⍬ 0 diff --git a/APL/2021/12.ipynb b/APL/2021/12.ipynb deleted file mode 100644 index 86172ff..0000000 --- a/APL/2021/12.ipynb +++ /dev/null @@ -1,117 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← '-'(≠⊆⊢)¨⊃⎕NGET '12.txt' 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "next ← {w←⍵⋄⊃{a b←⍺⋄a≡w:⍵,⊂b⋄b≡w:⍵,⊂a⋄⍵}/data,⊂⍬}\n", - "search ← {p v s←⍵⋄p≡'end':1⋄t←(∧/97≤⎕UCS p)∧∨/(p≡⊢)¨v⋄t∧s∨p≡'start':0⋄+/{search ⍵ (v∪⊂p) (t∨s)}¨next p}" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "3679\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "search 'start' ⍬ 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "107395\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "search 'start' ⍬ 0" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/13.apl b/APL/2021/13.apl new file mode 100644 index 0000000..0ad0b47 --- /dev/null +++ b/APL/2021/13.apl @@ -0,0 +1,8 @@ +dots folds ← {⍵⊆⍨0≠≢¨⍵}⊃⎕NGET '../.cache/2021/13' 1 +dots ← {⍎¨','(≠⊆⊢)⍵}¨dots +folds ← {c n←'='(≠⊆⊢)⊃⌽' '(≠⊆⊢)⍵⋄(⊃c)(⍎n)}¨folds +fold ← {c n←2⊃⍵⋄∪{x y←⍵⋄c≡'y':x(y⌊n+n-y)⋄(x⌊n+n-x)y}¨⊃⍵} +⎕ ← ≢fold dots (⊃folds) +dots ← ⊃{fold ⍵ ⍺}/(⌽folds),⊂dots +w h ← ⊃⌈/dots +⎕ ← ↑↑{,/⍵}¨↓{(⊂⌽⍵)∊dots:'##'⋄' '}¨1-⍨⍳(h+1)(w+1) diff --git a/APL/2021/13.ipynb b/APL/2021/13.ipynb deleted file mode 100644 index 309e9bd..0000000 --- a/APL/2021/13.ipynb +++ /dev/null @@ -1,120 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "dots folds ← {⍵⊆⍨0≠≢¨⍵}⊃⎕NGET '13.txt' 1\n", - "dots ← {⍎¨','(≠⊆⊢)⍵}¨dots\n", - "folds ← {c n←'='(≠⊆⊢)⊃⌽' '(≠⊆⊢)⍵⋄(⊃c)(⍎n)}¨folds" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "fold ← {c n←2⊃⍵⋄∪{x y←⍵⋄c≡'y':x(y⌊n+n-y)⋄(x⌊n+n-x)y}¨⊃⍵}" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "747\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "≢fold dots (⊃folds)" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/plain": " #### ###### ## ## ######## ###### #### ## ## ## ##\n## ## ## ## ## ## ## ## ## ## ## ## ## ## ##\n## ## ## ## ######## ## ## ## ## ## ## ########\n######## ###### ## ## ## ###### ## ## ## ## ##\n## ## ## ## ## ## ## ## ## ## ## ## ## ##\n## ## ## ## ## ## ######## ## #### #### ## ##" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dots ← ⊃{fold ⍵ ⍺}/(⌽folds),⊂dots\n", - "w h ← ⊃⌈/dots\n", - "↑↑{,/⍵}¨↓{(⊂⌽⍵)∊dots:'##'⋄' '}¨1-⍨⍳(h+1)(w+1)" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/14.apl b/APL/2021/14.apl new file mode 100644 index 0000000..ccfc966 --- /dev/null +++ b/APL/2021/14.apl @@ -0,0 +1,9 @@ +input ← ⊃⎕NGET '../.cache/2021/14' 1 +⎕PP ← 32 +template ← ⊃input +rules ← {(⍵⌷⍨⊢)¨1 2 7}¨2↓input +gr ← {k←⍵⋄{⊃⌽⊃⍵/⍨{k≡2↑⍵}¨⍵}rules} +next ← {{w←⍵⋄∪{k←⍵⋄⍵ (+/{(2⊃⍵)×k≡⊃⍵}¨w)}¨{⊃⍵}¨w}⊃,/{(a b) c←⍵⋄x←gr ⊃⍵⋄((a x)c)((x b)c)}¨⍵} +solve ← {{(⌈/⍵)-(⌊/⍵)}⊃⌽↓⍉{a b←⍵⋄({⊃⌽⍵}¨a) {⍺,+/⍵}⌸ b}↓⍉↑ (⊂((1↑template) 1)),(next⍣⍵) ↓{(⊃⍺)(≢⍵)}⌸2,/template} +⎕ ← solve 10 +⎕ ← solve 40 diff --git a/APL/2021/14.ipynb b/APL/2021/14.ipynb deleted file mode 100644 index 6d7fb42..0000000 --- a/APL/2021/14.ipynb +++ /dev/null @@ -1,122 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ⊃⎕NGET '14.txt' 1\n", - "⎕PP ← 32" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "template ← ⊃data\n", - "rules ← {(⍵⌷⍨⊢)¨1 2 7}¨2↓data\n", - "\n", - "gr ← {k←⍵⋄{⊃⌽⊃⍵/⍨{k≡2↑⍵}¨⍵}rules}\n", - "next ← {{w←⍵⋄∪{k←⍵⋄⍵ (+/{(2⊃⍵)×k≡⊃⍵}¨w)}¨{⊃⍵}¨w}⊃,/{(a b) c←⍵⋄x←gr ⊃⍵⋄((a x)c)((x b)c)}¨⍵}\n", - "solve ← {{(⌈/⍵)-(⌊/⍵)}⊃⌽↓⍉{a b←⍵⋄({⊃⌽⍵}¨a) {⍺,+/⍵}⌸ b}↓⍉↑ (⊂((1↑template) 1)),(next⍣⍵) ↓{(⊃⍺)(≢⍵)}⌸2,/template}" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "3247\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve 10" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "4110568157153\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve 40" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/15.apl b/APL/2021/15.apl new file mode 100644 index 0000000..036b660 --- /dev/null +++ b/APL/2021/15.apl @@ -0,0 +1,4 @@ +input ← ↑⍎¨¨⊃⎕NGET '../.cache/2021/15' 1 +solve←{d←⍵⋄h w←⍴d⋄max←+/∊d⋄⊃⌽∊({⊃⌊/⍵ (d+{⍉max,⍉¯1↓⍵}⍵)(d+{⍉max,⍨⍉1↓⍵}⍵)(d+{max,⍉¯1↓⍉⍵}⍵)(d+{max,⍨⍉1↓⍉⍵}⍵)}⍣(2×w+h))h w⍴0,(1-⍨w×h)⍴max} +⎕ ← solve input +⎕ ← solve ⍉⊃,/⍉¨,⌿⍉{1+⍨9|1-⍨input++/⍵}¨1-⍨⍳5 5 diff --git a/APL/2021/15.ipynb b/APL/2021/15.ipynb deleted file mode 100644 index 2efb001..0000000 --- a/APL/2021/15.ipynb +++ /dev/null @@ -1,116 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ↑⍎¨¨⊃⎕NGET '15.txt' 1" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "solve←{d←⍵⋄h w←⍴d⋄max←+/∊d⋄⊃⌽∊({⊃⌊/⍵ (d+{⍉max,⍉¯1↓⍵}⍵)(d+{⍉max,⍨⍉1↓⍵}⍵)(d+{max,⍉¯1↓⍉⍵}⍵)(d+{max,⍨⍉1↓⍉⍵}⍵)}⍣(2×w+h))h w⍴0,(1-⍨w×h)⍴max}" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "366\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve data" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "2829\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "solve ⍉⊃,/⍉¨,⌿⍉{1+⍨9|1-⍨data++/⍵}¨1-⍨⍳5 5" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/16.apl b/APL/2021/16.apl new file mode 100644 index 0000000..a7ef85a --- /dev/null +++ b/APL/2021/16.apl @@ -0,0 +1,12 @@ +input ← ⊃,/{⍵⊤⍨4⍴2}¨1-⍨('0123456789ABCDEF'⍸⊢)¨⊃⊃⎕NGET '../.cache/2021/16' 1 +⎕PP ← 32 +read ← {a b←⍵⋄2⊥input[1-⍨a+⍳b]} +rl ← {i x←⍵⋄c←read i 1⋄x←(x×16)+read(i+1)4⋄~c:(i+5)x⋄∇(i+5)x} +gv0 ← {{i c←⍵⋄i≥c:i 0 ⍬⋄i v x←solve i⋄i vs xs←∇i c⋄i(v+vs)(x,xs)}(⍵+15)(⍵+15+read ⍵ 15)} +gv1 ← {{i c←⍵⋄c≤0:i 0 ⍬⋄i v x←solve i⋄i vs xs←∇i(c-1)⋄i(v+vs)(x,xs)}(⍵+11)(read ⍵ 11)} +gv ← {0=read ⍵ 1:gv0 (⍵+1)⋄gv1 (⍵+1)} +op ← {t x←⍵⋄t=0:⊃+/x⋄t=1:⊃×/x⋄t=2:⊃⌊/x⋄t=3:⊃⌈/x⋄t=5:(⊃x)>2⊃x⋄t=6:(⊃x)<2⊃x⋄t=7:(⊃x)=2⊃x} +solve ← {i←⍵⋄v←read i 3⋄i←i+3⋄t←read i 3⋄i←i+3⋄t=4:{i x←⍵⋄i v x}rl i 0⋄i vs xs←gv i⋄i(v+vs)(op t xs)} +_ part1 part2 ← solve 1 +⎕ ← part1 +⎕ ← part2 diff --git a/APL/2021/16.ipynb b/APL/2021/16.ipynb deleted file mode 100644 index 7654b02..0000000 --- a/APL/2021/16.ipynb +++ /dev/null @@ -1,124 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "8fb56a69-e2e3-4a2e-9257-c78046f23f21", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "data ← ⊃,/{⍵⊤⍨4⍴2}¨1-⍨('0123456789ABCDEF'⍸⊢)¨⊃⊃⎕NGET '16.txt' 1\n", - "⎕PP ← 32" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "read ← {a b←⍵⋄2⊥data[1-⍨a+⍳b]}\n", - "rl ← {i x←⍵⋄c←read i 1⋄x←(x×16)+read(i+1)4⋄~c:(i+5)x⋄∇(i+5)x}\n", - "gv0 ← {{i c←⍵⋄i≥c:i 0 ⍬⋄i v x←solve i⋄i vs xs←∇i c⋄i(v+vs)(x,xs)}(⍵+15)(⍵+15+read ⍵ 15)}\n", - "gv1 ← {{i c←⍵⋄c≤0:i 0 ⍬⋄i v x←solve i⋄i vs xs←∇i(c-1)⋄i(v+vs)(x,xs)}(⍵+11)(read ⍵ 11)}\n", - "gv ← {0=read ⍵ 1:gv0 (⍵+1)⋄gv1 (⍵+1)}\n", - "op ← {t x←⍵⋄t=0:⊃+/x⋄t=1:⊃×/x⋄t=2:⊃⌊/x⋄t=3:⊃⌈/x⋄t=5:(⊃x)>2⊃x⋄t=6:(⊃x)<2⊃x⋄t=7:(⊃x)=2⊃x}\n", - "solve ← {i←⍵⋄v←read i 3⋄i←i+3⋄t←read i 3⋄i←i+3⋄t=4:{i x←⍵⋄i v x}rl i 0⋄i vs xs←gv i⋄i(v+vs)(op t xs)}\n", - "_ part1 part2 ← solve 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [ - { - "data": { - "text/html": "906\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "part1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "819324480368\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "part2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/2021/17.apl b/APL/2021/17.apl new file mode 100644 index 0000000..fa63a45 --- /dev/null +++ b/APL/2021/17.apl @@ -0,0 +1,4 @@ +(x1 x2) (y1 y2) ← {⍎¨'.'(≠⊆⊢)⊃','(≠⊆⊢)⍵}¨1↓'='(≠⊆⊢)⊃⊃⎕NGET '../.cache/2021/17' 1 +s ← {w←{x y vx vy←⍵⋄(x>x2)∨(yx2)∨(y3916\n" - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "⌈/∊{vy←⍵⋄{vx←⍵⋄y k←s vx vy⋄k×y}¨⍳x2}¨1-⍨y1+⍳500+1-y1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### Part 2" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - } - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/html": "2986\n" - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "+/∊{vy←⍵⋄{vx←⍵⋄y k←s vx vy⋄k}¨⍳x2}¨1-⍨y1+⍳500+1-y1" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } - } - ], - "metadata": { - "kernelspec": { - "display_name": "Dyalog APL", - "language": "apl", - "name": "dyalog-kernel" - }, - "language_info": { - "file_extension": ".apl", - "mimetype": "text/apl", - "name": "APL" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file diff --git a/APL/justfile b/APL/justfile new file mode 100644 index 0000000..a8671c8 --- /dev/null +++ b/APL/justfile @@ -0,0 +1,19 @@ +alias r := run +alias t := test +alias ty := test-year +alias ta := test-all + +_default: + @just --list + +run year day: + dyalogscript {{year}}/{{day}}.apl + +test year day: + @diff <(just run {{year}} {{day}}) <(cat ../.cache/{{year}}/{{trim_start_match(day, "0")}}.{1,2}) + +test-year year: + @set -e; for day in $(ls {{year}}); do just test {{year}} $(basename $day .apl); done + +test-all: + @set -e; for year in *; do [[ -d $year ]] || continue; just test-year $year; done diff --git a/README.md b/README.md index f63c41a..1ad4712 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ ## [2021](https://adventofcode.com/2021) ([ Rust](Rust/2021): 25/25 | [ Python](Python/2021): 25/25 | [ APL](APL/2021): 17/25) |Mo|Tu|We|Th|Fr|Sa|Su| |-|-|-|-|-|-|-| -|||[**1**](https://adventofcode.com/2021/day/1) [](Rust/2021/01.rs "Rust solution for 2021/01") [](Python/2021/01.ipynb "Python solution for 2021/01") [](APL/2021/01.ipynb "APL solution for 2021/01")|[**2**](https://adventofcode.com/2021/day/2) [](Rust/2021/02.rs "Rust solution for 2021/02") [](Python/2021/02.ipynb "Python solution for 2021/02") [](APL/2021/02.ipynb "APL solution for 2021/02")|[**3**](https://adventofcode.com/2021/day/3) [](Rust/2021/03.rs "Rust solution for 2021/03") [](Python/2021/03.ipynb "Python solution for 2021/03") [](APL/2021/03.ipynb "APL solution for 2021/03")|[**4**](https://adventofcode.com/2021/day/4) [](Rust/2021/04.rs "Rust solution for 2021/04") [](Python/2021/04.ipynb "Python solution for 2021/04") [](APL/2021/04.ipynb "APL solution for 2021/04")|[**5**](https://adventofcode.com/2021/day/5) [](Rust/2021/05.rs "Rust solution for 2021/05") [](Python/2021/05.ipynb "Python solution for 2021/05") [](APL/2021/05.ipynb "APL solution for 2021/05")| -|[**6**](https://adventofcode.com/2021/day/6) [](Rust/2021/06.rs "Rust solution for 2021/06") [](Python/2021/06.ipynb "Python solution for 2021/06") [](APL/2021/06.ipynb "APL solution for 2021/06")|[**7**](https://adventofcode.com/2021/day/7) [](Rust/2021/07.rs "Rust solution for 2021/07") [](Python/2021/07.ipynb "Python solution for 2021/07") [](APL/2021/07.ipynb "APL solution for 2021/07")|[**8**](https://adventofcode.com/2021/day/8) [](Rust/2021/08.rs "Rust solution for 2021/08") [](Python/2021/08.ipynb "Python solution for 2021/08") [](APL/2021/08.ipynb "APL solution for 2021/08")|[**9**](https://adventofcode.com/2021/day/9) [](Rust/2021/09.rs "Rust solution for 2021/09") [](Python/2021/09.ipynb "Python solution for 2021/09") [](APL/2021/09.ipynb "APL solution for 2021/09")|[**10**](https://adventofcode.com/2021/day/10) [](Rust/2021/10.rs "Rust solution for 2021/10") [](Python/2021/10.ipynb "Python solution for 2021/10") [](APL/2021/10.ipynb "APL solution for 2021/10")|[**11**](https://adventofcode.com/2021/day/11) [](Rust/2021/11.rs "Rust solution for 2021/11") [](Python/2021/11.ipynb "Python solution for 2021/11") [](APL/2021/11.ipynb "APL solution for 2021/11")|[**12**](https://adventofcode.com/2021/day/12) [](Rust/2021/12.rs "Rust solution for 2021/12") [](Python/2021/12.ipynb "Python solution for 2021/12") [](APL/2021/12.ipynb "APL solution for 2021/12")| -|[**13**](https://adventofcode.com/2021/day/13) [](Rust/2021/13.rs "Rust solution for 2021/13") [](Python/2021/13.ipynb "Python solution for 2021/13") [](APL/2021/13.ipynb "APL solution for 2021/13")|[**14**](https://adventofcode.com/2021/day/14) [](Rust/2021/14.rs "Rust solution for 2021/14") [](Python/2021/14.ipynb "Python solution for 2021/14") [](APL/2021/14.ipynb "APL solution for 2021/14")|[**15**](https://adventofcode.com/2021/day/15) [](Rust/2021/15.rs "Rust solution for 2021/15") [](Python/2021/15.ipynb "Python solution for 2021/15") [](APL/2021/15.ipynb "APL solution for 2021/15")|[**16**](https://adventofcode.com/2021/day/16) [](Rust/2021/16.rs "Rust solution for 2021/16") [](Python/2021/16.ipynb "Python solution for 2021/16") [](APL/2021/16.ipynb "APL solution for 2021/16")|[**17**](https://adventofcode.com/2021/day/17) [](Rust/2021/17.rs "Rust solution for 2021/17") [](Python/2021/17.ipynb "Python solution for 2021/17") [](APL/2021/17.ipynb "APL solution for 2021/17")|[**18**](https://adventofcode.com/2021/day/18) [](Rust/2021/18.rs "Rust solution for 2021/18") [](Python/2021/18.ipynb "Python solution for 2021/18")|[**19**](https://adventofcode.com/2021/day/19) [](Rust/2021/19.rs "Rust solution for 2021/19") [](Python/2021/19.ipynb "Python solution for 2021/19")| +|||[**1**](https://adventofcode.com/2021/day/1) [](Rust/2021/01.rs "Rust solution for 2021/01") [](Python/2021/01.ipynb "Python solution for 2021/01") [](APL/2021/01.apl "APL solution for 2021/01")|[**2**](https://adventofcode.com/2021/day/2) [](Rust/2021/02.rs "Rust solution for 2021/02") [](Python/2021/02.ipynb "Python solution for 2021/02") [](APL/2021/02.apl "APL solution for 2021/02")|[**3**](https://adventofcode.com/2021/day/3) [](Rust/2021/03.rs "Rust solution for 2021/03") [](Python/2021/03.ipynb "Python solution for 2021/03") [](APL/2021/03.apl "APL solution for 2021/03")|[**4**](https://adventofcode.com/2021/day/4) [](Rust/2021/04.rs "Rust solution for 2021/04") [](Python/2021/04.ipynb "Python solution for 2021/04") [](APL/2021/04.apl "APL solution for 2021/04")|[**5**](https://adventofcode.com/2021/day/5) [](Rust/2021/05.rs "Rust solution for 2021/05") [](Python/2021/05.ipynb "Python solution for 2021/05") [](APL/2021/05.apl "APL solution for 2021/05")| +|[**6**](https://adventofcode.com/2021/day/6) [](Rust/2021/06.rs "Rust solution for 2021/06") [](Python/2021/06.ipynb "Python solution for 2021/06") [](APL/2021/06.apl "APL solution for 2021/06")|[**7**](https://adventofcode.com/2021/day/7) [](Rust/2021/07.rs "Rust solution for 2021/07") [](Python/2021/07.ipynb "Python solution for 2021/07") [](APL/2021/07.apl "APL solution for 2021/07")|[**8**](https://adventofcode.com/2021/day/8) [](Rust/2021/08.rs "Rust solution for 2021/08") [](Python/2021/08.ipynb "Python solution for 2021/08") [](APL/2021/08.apl "APL solution for 2021/08")|[**9**](https://adventofcode.com/2021/day/9) [](Rust/2021/09.rs "Rust solution for 2021/09") [](Python/2021/09.ipynb "Python solution for 2021/09") [](APL/2021/09.apl "APL solution for 2021/09")|[**10**](https://adventofcode.com/2021/day/10) [](Rust/2021/10.rs "Rust solution for 2021/10") [](Python/2021/10.ipynb "Python solution for 2021/10") [](APL/2021/10.apl "APL solution for 2021/10")|[**11**](https://adventofcode.com/2021/day/11) [](Rust/2021/11.rs "Rust solution for 2021/11") [](Python/2021/11.ipynb "Python solution for 2021/11") [](APL/2021/11.apl "APL solution for 2021/11")|[**12**](https://adventofcode.com/2021/day/12) [](Rust/2021/12.rs "Rust solution for 2021/12") [](Python/2021/12.ipynb "Python solution for 2021/12") [](APL/2021/12.apl "APL solution for 2021/12")| +|[**13**](https://adventofcode.com/2021/day/13) [](Rust/2021/13.rs "Rust solution for 2021/13") [](Python/2021/13.ipynb "Python solution for 2021/13") [](APL/2021/13.apl "APL solution for 2021/13")|[**14**](https://adventofcode.com/2021/day/14) [](Rust/2021/14.rs "Rust solution for 2021/14") [](Python/2021/14.ipynb "Python solution for 2021/14") [](APL/2021/14.apl "APL solution for 2021/14")|[**15**](https://adventofcode.com/2021/day/15) [](Rust/2021/15.rs "Rust solution for 2021/15") [](Python/2021/15.ipynb "Python solution for 2021/15") [](APL/2021/15.apl "APL solution for 2021/15")|[**16**](https://adventofcode.com/2021/day/16) [](Rust/2021/16.rs "Rust solution for 2021/16") [](Python/2021/16.ipynb "Python solution for 2021/16") [](APL/2021/16.apl "APL solution for 2021/16")|[**17**](https://adventofcode.com/2021/day/17) [](Rust/2021/17.rs "Rust solution for 2021/17") [](Python/2021/17.ipynb "Python solution for 2021/17") [](APL/2021/17.apl "APL solution for 2021/17")|[**18**](https://adventofcode.com/2021/day/18) [](Rust/2021/18.rs "Rust solution for 2021/18") [](Python/2021/18.ipynb "Python solution for 2021/18")|[**19**](https://adventofcode.com/2021/day/19) [](Rust/2021/19.rs "Rust solution for 2021/19") [](Python/2021/19.ipynb "Python solution for 2021/19")| |[**20**](https://adventofcode.com/2021/day/20) [](Rust/2021/20.rs "Rust solution for 2021/20") [](Python/2021/20.ipynb "Python solution for 2021/20")|[**21**](https://adventofcode.com/2021/day/21) [](Rust/2021/21.rs "Rust solution for 2021/21") [](Python/2021/21.ipynb "Python solution for 2021/21")|[**22**](https://adventofcode.com/2021/day/22) [](Rust/2021/22.rs "Rust solution for 2021/22") [](Python/2021/22.ipynb "Python solution for 2021/22")|[**23**](https://adventofcode.com/2021/day/23) [](Rust/2021/23.rs "Rust solution for 2021/23") [](Python/2021/23.ipynb "Python solution for 2021/23")|[**24**](https://adventofcode.com/2021/day/24) [](Rust/2021/24.rs "Rust solution for 2021/24") [](Python/2021/24.ipynb "Python solution for 2021/24")|[**25**](https://adventofcode.com/2021/day/25) [](Rust/2021/25.rs "Rust solution for 2021/25") [](Python/2021/25.ipynb "Python solution for 2021/25")|26| |27|28|29|30|31||| diff --git a/flake.nix b/flake.nix index e7564c5..9560222 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,13 @@ outputs = {nixpkgs, ...}: let system = "x86_64-linux"; - pkgs = import nixpkgs {inherit system;}; + pkgs = import nixpkgs { + inherit system; + config.allowUnfreePredicate = pkg: + builtins.elem (nixpkgs.lib.getName pkg) [ + "dyalog" + ]; + }; downloadInput = pkgs.stdenvNoCC.mkDerivation { name = "aoc-download-input"; @@ -56,6 +62,11 @@ (haskellPackages.ghcWithPackages (p: with p; [regex-tdfa])) haskell-language-server ormolu # haskell code formatter + + # APL + (dyalog.override { + acceptLicense = true; + }) ]; PYTHONPATH = "."; }; diff --git a/scripts/generate-readme.py b/scripts/generate-readme.py index 0a369c6..32df846 100644 --- a/scripts/generate-readme.py +++ b/scripts/generate-readme.py @@ -3,7 +3,7 @@ from datetime import date from pathlib import Path names = {"rs": "Rust", "hs": "Haskell", "py": "Python", "apl": "APL"} -exts = {"rs": [".rs"], "hs": [".hs"], "py": [".py", ".ipynb", ""], "apl": [".ipynb"]} +exts = {"rs": [".rs"], "hs": [".hs"], "py": [".py", ".ipynb", ""], "apl": [".apl"]} def logo(lang, height=12):