From b6512dc6c1db831c88ba99d7b9c279f862602c33 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Sun, 15 Dec 2024 04:20:55 +0000 Subject: [PATCH] day 14 ivy solution --- day14/input.ivy | 1 + day14/sol.ivy | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 day14/input.ivy create mode 100644 day14/sol.ivy diff --git a/day14/input.ivy b/day14/input.ivy new file mode 100644 index 0000000..f21c8b8 --- /dev/null +++ b/day14/input.ivy @@ -0,0 +1 @@ +input = 500 4 rho 18 60 90 -17 4 66 -43 10 88 50 19 62 33 42 99 -68 8 85 78 -29 49 78 -1 -52 39 73 8 -18 61 8 34 -12 82 84 19 -1 4 86 71 -32 23 99 5 33 68 3 17 74 84 56 78 89 38 74 15 27 34 55 -85 24 78 41 -61 -6 34 58 40 -79 23 96 -87 81 2 31 -72 -95 46 88 16 -87 32 65 47 -55 56 69 1 -76 24 86 90 40 87 4 -53 14 30 38 56 -99 64 37 -76 -81 93 51 -98 -96 14 4 -5 95 46 101 -36 -5 83 61 79 45 31 11 78 19 42 85 -27 92 0 30 -97 -71 51 76 50 99 89 30 76 -62 98 8 -45 93 19 101 -27 68 62 30 -27 -79 62 72 -66 -24 51 68 -68 68 42 34 66 -20 81 14 -6 -91 69 82 83 22 11 66 98 -18 23 81 -41 6 53 48 -31 55 81 46 -39 28 49 7 24 -53 44 22 15 -42 6 24 -20 63 35 43 22 38 31 23 15 22 92 74 -73 71 29 70 39 17 81 62 52 -49 96 65 -57 -9 36 70 82 34 45 67 7 14 27 79 -3 88 64 26 85 -78 45 85 75 92 65 97 68 -53 20 100 -85 -6 80 23 -57 97 81 3 -32 91 95 18 -22 19 28 61 98 24 17 57 -3 -55 25 67 -20 96 44 4 83 -60 98 26 -81 11 83 55 -14 -37 50 55 61 1 76 90 55 -34 14 49 64 93 20 8 39 -81 20 88 98 85 75 4 -43 -16 55 18 -93 15 13 7 -63 -84 100 24 -6 -99 1 87 -64 -74 52 100 15 33 78 24 -91 46 86 32 -57 97 96 43 20 -55 70 67 26 -4 86 79 -36 57 27 80 98 -52 2 1 37 81 95 63 -81 -2 52 57 -60 75 22 6 -62 57 82 43 94 -99 58 2 42 20 74 4 -48 -88 14 35 -80 -78 61 13 -92 -67 18 43 17 68 28 28 -11 53 55 15 84 -53 16 59 -74 15 95 80 -21 37 68 43 10 48 88 93 -90 47 54 49 10 -60 53 74 -27 -38 25 97 -53 2 50 0 -94 -94 99 33 -13 18 66 74 -15 -1 28 47 13 11 55 64 -57 -3 16 43 -6 -79 20 12 98 -98 24 46 42 21 77 40 44 79 20 64 -96 -86 1 18 -30 63 86 83 95 81 43 73 -30 19 18 79 47 75 71 49 -37 -26 16 66 -71 27 2 101 -22 33 13 60 -23 -22 79 57 -13 38 82 100 -88 -98 25 31 23 -81 93 63 -48 10 44 16 -77 8 56 101 8 -91 11 29 21 -40 65 38 -26 -41 70 8 69 -5 25 80 -87 85 74 55 -28 11 96 93 -62 21 65 17 -75 56 41 99 -28 -49 37 90 54 -96 30 89 -27 -97 95 55 20 93 92 64 -49 89 25 32 -28 63 47 66 33 85 96 43 -64 -27 78 10 93 33 99 67 -43 59 38 24 99 -16 48 22 28 -53 74 18 -48 -95 73 6 26 -91 77 5 -25 98 59 4 50 26 91 24 -38 -70 4 82 -30 20 52 87 33 -1 78 8 -32 -98 84 50 45 66 25 67 22 96 77 75 85 -8 2 75 -95 40 60 8 -88 94 78 32 39 15 54 89 9 -28 100 75 -81 13 19 40 66 -63 43 25 -37 24 16 66 -62 -86 94 81 -32 78 30 76 73 -11 25 65 14 -93 69 86 -16 -59 43 26 -85 -88 54 8 -25 32 10 98 69 -40 50 78 42 3 93 43 -44 -85 42 20 84 -6 99 14 28 26 58 85 17 61 1 50 89 -79 92 11 -39 77 90 62 -13 -79 80 55 -85 -13 19 4 93 18 52 69 -68 -52 76 8 52 43 83 0 -56 55 24 101 -55 -57 67 47 42 41 83 93 36 78 59 65 -84 -76 19 24 14 -99 19 23 -96 -40 29 93 53 56 48 19 -68 71 95 47 7 -34 5 51 63 54 61 87 -17 30 12 41 47 28 79 99 86 2 52 37 -24 -11 89 66 -18 33 60 33 -1 -1 4 39 46 -61 11 44 59 -20 68 15 -75 72 51 69 -68 -4 95 42 -57 24 10 19 21 -60 2 30 12 80 80 22 64 56 73 15 -6 56 46 35 -69 -41 40 27 57 8 88 44 53 -68 56 88 -68 51 20 12 38 67 7 61 51 37 13 100 53 -95 3 39 5 45 18 88 29 -25 95 90 -72 99 63 86 -91 51 47 81 63 81 78 77 87 -14 59 64 -9 48 39 86 -93 57 97 46 45 45 50 64 99 99 15 65 -97 -84 22 84 57 -61 49 86 93 -28 19 76 -45 58 57 7 25 -29 9 14 -80 87 68 59 -92 -38 96 30 -31 8 16 48 72 -34 0 67 70 6 33 74 -86 -15 46 11 -6 40 66 42 86 -27 51 53 33 86 18 23 47 -2 81 91 78 -39 57 28 -95 -94 75 61 10 10 7 34 38 -13 93 31 19 -95 45 39 -51 18 10 13 -4 72 21 76 -44 -31 81 71 3 -48 82 69 60 -96 47 11 41 -33 72 86 94 -25 21 45 90 -51 15 19 57 -75 52 59 8 7 56 24 -67 4 17 26 71 -47 59 97 21 12 74 16 -24 77 86 97 -32 20 58 96 -79 57 91 48 -33 -15 44 80 -77 6 8 26 98 94 8 9 -97 -19 70 32 -7 1 20 85 73 -18 20 94 81 26 86 22 70 70 53 19 92 -40 34 44 65 72 94 11 -56 36 97 10 -47 19 10 101 -4 -49 51 66 -85 -18 39 17 -33 13 98 82 -53 16 18 61 82 -65 99 100 11 40 34 8 -85 -50 63 63 -50 -62 54 39 92 -51 49 77 84 88 20 69 39 -7 95 65 96 -89 42 40 -19 16 50 4 -14 99 23 47 21 -89 64 60 -10 -76 53 100 84 -70 91 60 94 -17 32 36 -78 -99 98 68 -39 72 69 81 -93 -93 70 5 -85 35 10 96 14 -53 51 32 -93 66 52 87 -51 6 81 17 85 98 5 38 -55 -58 72 17 18 8 59 81 63 -85 66 9 -36 -53 15 55 -30 83 1 29 -39 77 56 85 50 -90 50 88 -68 57 73 22 42 -92 48 39 18 43 66 56 43 86 23 57 73 65 76 87 1 85 90 83 -40 -11 82 20 -54 90 43 95 -48 6 46 10 24 -74 63 85 -43 40 89 101 11 81 13 47 22 -82 48 92 41 -56 100 8 -82 90 15 39 -3 8 46 66 -60 -55 23 91 56 2 68 66 84 38 10 46 -21 -65 62 49 25 -75 26 92 -70 -62 10 13 -29 -2 79 49 -57 45 99 12 79 29 59 48 63 31 15 23 8 -67 61 35 93 -41 73 11 60 43 74 26 52 15 5 82 -4 -66 46 14 -38 76 71 8 -48 97 35 9 75 -84 91 89 28 47 61 84 -17 22 38 55 48 37 3 68 62 69 96 10 96 -43 1 67 -46 62 65 95 -54 -93 57 63 42 34 93 11 53 -50 38 50 40 -65 88 4 -48 57 100 30 -2 -8 33 19 -96 53 42 7 32 12 62 7 46 58 91 6 -73 36 58 41 50 76 67 7 -25 -95 95 49 -38 89 22 93 13 54 95 14 37 -19 35 25 -26 -57 58 97 -67 -63 18 28 63 75 43 27 66 94 95 49 -31 42 95 93 -89 23 0 35 12 56 70 72 18 34 100 67 19 24 82 18 -93 73 50 60 67 24 30 28 39 -34 2 61 12 -35 24 65 -20 58 95 27 48 -64 92 68 -20 60 90 55 61 -72 35 80 75 -94 30 37 -27 -37 0 52 87 45 7 60 -38 -48 15 7 98 4 76 98 -1 -16 32 6 -1 -29 100 58 -47 -77 64 62 34 27 13 81 46 -14 75 77 18 -25 35 44 -2 38 30 87 -95 33 73 36 66 -82 50 85 -2 -52 23 43 37 74 55 11 92 46 44 57 48 10 1 9 54 46 81 66 -15 -35 99 91 71 54 5 80 -72 20 85 74 11 -76 10 61 14 48 60 18 42 32 21 88 4 -29 78 43 -67 76 39 69 9 -13 89 26 -13 -82 27 50 -94 65 69 45 8 62 32 83 40 -1 54 0 8 -77 73 21 -32 -12 34 39 43 29 31 9 98 12 11 20 73 -88 44 71 93 -37 22 20 89 -57 95 58 37 -86 79 24 -30 -46 35 17 -78 32 13 90 -46 99 55 83 8 -52 30 66 -54 71 68 70 -12 98 43 50 48 -93 99 57 87 -48 82 83 -99 95 35 23 -78 -6 0 102 -89 -22 39 77 -78 -83 50 72 -96 -79 20 69 -91 -44 9 21 46 15 44 90 91 33 14 49 -7 -10 65 52 -16 62 13 0 91 83 78 65 34 -31 65 92 59 95 68 43 -32 -55 45 34 -94 -30 20 69 -8 3 45 67 -75 -94 63 14 -33 -77 93 48 -91 -17 32 85 48 82 99 80 95 -94 22 25 30 -88 68 14 50 -15 17 100 -63 40 21 53 50 23 23 43 23 -55 4 76 63 58 79 9 56 -6 81 95 79 85 75 50 68 92 40 28 -34 -9 51 4 49 -7 40 81 -32 2 52 14 15 -23 94 90 -95 24 71 82 -24 -42 51 97 -43 71 3 79 31 87 53 25 -27 -75 29 8 57 98 74 52 -6 58 3 8 -48 81 51 95 -23 -49 4 22 78 -17 85 39 36 59 39 8 -49 47 5 40 -29 -85 75 37 -57 -6 8 6 -38 -5 3 32 96 -92 2 96 54 -87 66 75 33 -25 81 37 41 -24 28 54 -72 36 43 65 40 -89 51 0 -26 40 56 64 25 -79 6 38 18 60 32 97 -79 -88 12 5 -79 54 38 72 -19 -29 21 51 -78 -32 33 27 -34 13 71 72 -43 -83 68 70 -50 51 72 82 68 54 64 35 -79 21 diff --git a/day14/sol.ivy b/day14/sol.ivy new file mode 100644 index 0000000..c5ba7b5 --- /dev/null +++ b/day14/sol.ivy @@ -0,0 +1,38 @@ + +) get "input.ivy" + +dims = 101 103 # width, height + +op t steps A = (A[;1 2] + t * A[;3 4]) mod dims + +op show coords = + pic = (*/dims) rho '.' + pic[dims decode transp coords] = '#' + transp dims rho pic + +op qscore coords = + x = coords[;1] + y = coords[;2] + m = floor dims / 2 + q1 = +/ (x < m[1]) and (y < m[2]) + q2 = +/ (x > m[1]) and (y < m[2]) + q3 = +/ (x < m[1]) and (y > m[2]) + q4 = +/ (x > m[1]) and (y > m[2]) + */(q1, q2, q3, q4) + +# qscore@ (iota */dims) @steps A + +op v minq t = + t < 0: v[1] + q = qscore (t steps v[3]) + q < v[2]: (t, q, box v[3]) minq (t-1) + v minq (t-1) + +op find A = (-1 1e100, box A) minq (*/dims) + +#show 8270 steps input +qscore 100 steps input + +t = find input +show (t steps input) +"t = ", t