Uiua, 46 44 42 40 39 3838 35 bytes
⊏↧5/◇+×+1⇡4◇+\+{⇌.⊞=.⊙⟜¤⟜=}⇡+1×2.:$ /\|-|O\/O
Try it!Try it! I submitted this on the day of the 2024 solar eclipse, which is fitting for a challenge about the sun. (Edit - the eclipse was beautiful! I saw it at around 85%-90% coverage)
At one point this borrowed some logic from randomra’s very clever J solutionCertainly my most well-golfed Uiua submission to-date. I have had a lot of different ideas and methods to save bytes and frequently switched much of the approach around a lot, but finally I foundhave this at a shorter solution usingstate where I'd be happy if I don't find anything more.
Omnikar's very clever idea in the Uiua discord to use /+\+
instead of multiplying each term by a different method.factor helped me save 3 bytes! 38 → 35
Outdated explanationExplanation:
Consider the input 3. We double this and add 1 to get the side length 7, and take the range from 0 up to it.
[0 1 2 3 4 5 6]
FromUnderneath this we startpush a copy with a mask of where the identity matrixoriginal input appears, and a reversed"fixed" (wrapped in an array) copy: of that.
0[0 0 0 01 0 0 10] 1[[0 0 0 01 0 0 0
00]] 0 0 0 0[0 1 02 3 4 5 06]
Using the range at the top of the stack, push the identity matrix and a reversed copy.
1 0 0 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0 0
0 0 0 1 0 0 0 0 0 0 1 0 0 0
0 0 1[[1 0 0 0 0 0 0] 0 0[[0 0 0 10 0 0 1]
0 [0 1 0 0 0 0 00] 0[0 0 0 0 0 1 00]
1 0 0 0 0 0 0 0 0 0 0 0 0 1
Also make the array of this many zeros with a 1 at the position of the original input:
0 0 0 1 0 0 0
Create a square matrix of this, and a transposed copy:
0 0 0 [0 0 1 0 0 0 0] [0 0 0 0 1 0 0 00]
0[0 0 0 01 0 0 00] 0[[0 0 0 1 0 0 0
00]] 0 0 [0 0 0 1 0 0 0] 0 [0 0 0 1 0 0 00]
1 1 1 1 1 1 1 0 0 0 1 0 0 0
0 0 0 [0 0 0 0 1 0 0] 0 0[0 0 1 0 0 0 0]
0 0 0 [0 0 0 0 0 1 0] 0 0 0[0 1 0 0 0
0 0 0]
[0 0 0 0 0 0 1]] 0[1 0 0 1 0 0 0 0]]
Then we take these 4 matrices in an array and multiply them by 1, 2, 3, and 4 respectivelyTake their cumulative sums:
0[[0 0 0 1 0 0 0 1] 0 0[[1 0 0 0 0 0
0 01] [[1 0 10 0 0 0 1] 0 0[[1 0 0 01 0 0 1]
[0 0 0 0 0 1 00] 0 0 [0 01 0 0 0 01 00] 0
0 0 0 [0 1 0 0 0 1 0] 2 2 2 2[0 21 20 21 0 1 0]
[0 0 0 0 1 0 00] 0 0[0 0 01 0 01 0 0
00] 0 [0 0 1 0 01 0 0] 0 0 0[0 0 01 01 1 0 0]
0 [0 0 0 1 0 0 00] 0 0[0 0 0 02 0 0
3 00] 0 0 0 0[1 01 1 3 01 01 01] 0 0 0 [1 1 1 4 1 1 1]
0 3[0 0 01 0 0 0 0] 0 0 0[0 0 1 0 41 0
0 00] 3 0 [0 0 1 0 1 0 0] 0 0 0[0 0 41 01 1 0 0]
0 0[0 01 30 0 0 0 0] 0 0 0[0 41 0 0 0
0 01 00] 0 3 0 0[0 1 0 0 0 41 00] 0 [0 1 0 1 0 1 0]
0 0[1 0 0 0 30 0 0]] 0 4[1 0 0 0 0 0
0 1]] [1 0 0 0 0 0 31]] 4[1 0 0 01 0 0 01]]
Sum them all togetherNotice that adding the fixed version of the list adds to each column, while the non-fixed version adds to each row.
Now, we sum the cumulative sums:
3[[3 0 0 1 0 0 4 4]
0 [0 3 0 1 0 4 0 0]
0 [0 0 3 1 4 0 0 0]
2 [2 2 2 10 2 2 2 2]
0 [0 0 4 1 3 0 0 0]
0 [0 4 0 1 0 3 00]
4 0[4 0 0 1 0 0 33]]
3[[3 0 0 1 0 0 4 4]
0 [0 3 0 1 0 4 0 0]
0 [0 0 3 1 4 0 0 0]
2 [2 2 2 5 2 2 2 2]
0 [0 0 4 1 3 0 0 0]
0 [0 4 0 1 0 3 00]
4 [4 0 0 1 0 0 33]]