Is this Pascal's Matrix?Diamondize a MatrixCalculate the Kronecker sum of two matricesMatrix TrigonometryIndex sum and strip my matrixDo Matrix Multiplication!Is the matrix rank-one?Fold up a matrix!Is this a Weyr matrix?Beware of the matrix tornado!Matrix Jigsaw Puzzles

15% tax on $7.5k earnings. Is that right?

Creepy dinosaur pc game identification

What should you do if you miss a job interview (deliberately)?

How should I respond when I lied about my education and the company finds out through background check?

Why is this estimator biased?

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

When were female captains banned from Starfleet?

On a tidally locked planet, would time be quantized?

It grows, but water kills it

Does malloc reserve more space while allocating memory?

Can disgust be a key component of horror?

How does a computer interpret real numbers?

Why should universal income be universal?

Does Doodling or Improvising on the Piano Have Any Benefits?

Does the Linux kernel need a file system to run?

Quoting Keynes in a lecture

Is this toilet slogan correct usage of the English language?

Plot of a tornado-shaped surface

Multiplicative persistence

Why did the EU agree to delay the Brexit deadline?

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Redundant comparison & "if" before assignment

How to cover method return statement in Apex Class?



Is this Pascal's Matrix?


Diamondize a MatrixCalculate the Kronecker sum of two matricesMatrix TrigonometryIndex sum and strip my matrixDo Matrix Multiplication!Is the matrix rank-one?Fold up a matrix!Is this a Weyr matrix?Beware of the matrix tornado!Matrix Jigsaw Puzzles













24












$begingroup$


In Pascal's triangle each number is the sum of the two numbers directly above it, treating empty spots as zero:



Source: https://en.wikipedia.org/wiki/File:Pascal_triangle_small.png



By rotating the triangle, we can cut out square matrices of varying sizes and rotations which I will call Pascal's matrices. Note that those matrices always need to contain the top $1$. Here are some examples:



1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20

6 3 1
3 2 1
1 1 1

1 5 15 35 70
1 4 10 20 35
1 3 6 10 15
1 2 3 4 5
1 1 1 1 1

1

1 1
2 1


The Task



Given a square matrix containing positive numbers in any reasonable format, decide if it is a Pascal's matrix.



Decide means to either return truthy or falsy values depending on whether the input is a Pascal's matrix, or to fix two constant values and return one for the true inputs and the other for false inputs.



This is code-golf, so try to use as few bytes as possible in the language of your choice. The shortest code in each language wins, thus I will not accept an answer.



Test cases



True



[[1, 1, 1, 1], [1, 2, 3, 4], [1, 3, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [3, 2, 1], [1, 1, 1]]
[[1, 5, 15, 35, 70], [1, 4, 10, 20, 35], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]
[[1]]
[[1, 1], [2, 1]]


False



[[2]]
[[1, 2], [2, 1]]
[[1, 1], [3, 1]]
[[1, 1, 1, 1], [1, 2, 3, 4], [1, 4, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [1, 1, 1], [3, 2, 1]]
[[2, 2, 2, 2], [2, 4, 6, 8], [2, 6, 12, 20], [2, 8, 20, 40]]
[[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]
[[1, 5, 15, 34, 70], [1, 4, 10, 20, 34], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]









share|improve this question











$endgroup$











  • $begingroup$
    Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
    $endgroup$
    – Kevin Cruijssen
    Mar 19 at 9:40











  • $begingroup$
    @KevinCruijssen Thanks, added.
    $endgroup$
    – Laikoni
    Mar 19 at 12:16















24












$begingroup$


In Pascal's triangle each number is the sum of the two numbers directly above it, treating empty spots as zero:



Source: https://en.wikipedia.org/wiki/File:Pascal_triangle_small.png



By rotating the triangle, we can cut out square matrices of varying sizes and rotations which I will call Pascal's matrices. Note that those matrices always need to contain the top $1$. Here are some examples:



1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20

6 3 1
3 2 1
1 1 1

1 5 15 35 70
1 4 10 20 35
1 3 6 10 15
1 2 3 4 5
1 1 1 1 1

1

1 1
2 1


The Task



Given a square matrix containing positive numbers in any reasonable format, decide if it is a Pascal's matrix.



Decide means to either return truthy or falsy values depending on whether the input is a Pascal's matrix, or to fix two constant values and return one for the true inputs and the other for false inputs.



This is code-golf, so try to use as few bytes as possible in the language of your choice. The shortest code in each language wins, thus I will not accept an answer.



Test cases



True



[[1, 1, 1, 1], [1, 2, 3, 4], [1, 3, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [3, 2, 1], [1, 1, 1]]
[[1, 5, 15, 35, 70], [1, 4, 10, 20, 35], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]
[[1]]
[[1, 1], [2, 1]]


False



[[2]]
[[1, 2], [2, 1]]
[[1, 1], [3, 1]]
[[1, 1, 1, 1], [1, 2, 3, 4], [1, 4, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [1, 1, 1], [3, 2, 1]]
[[2, 2, 2, 2], [2, 4, 6, 8], [2, 6, 12, 20], [2, 8, 20, 40]]
[[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]
[[1, 5, 15, 34, 70], [1, 4, 10, 20, 34], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]









share|improve this question











$endgroup$











  • $begingroup$
    Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
    $endgroup$
    – Kevin Cruijssen
    Mar 19 at 9:40











  • $begingroup$
    @KevinCruijssen Thanks, added.
    $endgroup$
    – Laikoni
    Mar 19 at 12:16













24












24








24


2



$begingroup$


In Pascal's triangle each number is the sum of the two numbers directly above it, treating empty spots as zero:



Source: https://en.wikipedia.org/wiki/File:Pascal_triangle_small.png



By rotating the triangle, we can cut out square matrices of varying sizes and rotations which I will call Pascal's matrices. Note that those matrices always need to contain the top $1$. Here are some examples:



1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20

6 3 1
3 2 1
1 1 1

1 5 15 35 70
1 4 10 20 35
1 3 6 10 15
1 2 3 4 5
1 1 1 1 1

1

1 1
2 1


The Task



Given a square matrix containing positive numbers in any reasonable format, decide if it is a Pascal's matrix.



Decide means to either return truthy or falsy values depending on whether the input is a Pascal's matrix, or to fix two constant values and return one for the true inputs and the other for false inputs.



This is code-golf, so try to use as few bytes as possible in the language of your choice. The shortest code in each language wins, thus I will not accept an answer.



Test cases



True



[[1, 1, 1, 1], [1, 2, 3, 4], [1, 3, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [3, 2, 1], [1, 1, 1]]
[[1, 5, 15, 35, 70], [1, 4, 10, 20, 35], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]
[[1]]
[[1, 1], [2, 1]]


False



[[2]]
[[1, 2], [2, 1]]
[[1, 1], [3, 1]]
[[1, 1, 1, 1], [1, 2, 3, 4], [1, 4, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [1, 1, 1], [3, 2, 1]]
[[2, 2, 2, 2], [2, 4, 6, 8], [2, 6, 12, 20], [2, 8, 20, 40]]
[[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]
[[1, 5, 15, 34, 70], [1, 4, 10, 20, 34], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]









share|improve this question











$endgroup$




In Pascal's triangle each number is the sum of the two numbers directly above it, treating empty spots as zero:



Source: https://en.wikipedia.org/wiki/File:Pascal_triangle_small.png



By rotating the triangle, we can cut out square matrices of varying sizes and rotations which I will call Pascal's matrices. Note that those matrices always need to contain the top $1$. Here are some examples:



1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20

6 3 1
3 2 1
1 1 1

1 5 15 35 70
1 4 10 20 35
1 3 6 10 15
1 2 3 4 5
1 1 1 1 1

1

1 1
2 1


The Task



Given a square matrix containing positive numbers in any reasonable format, decide if it is a Pascal's matrix.



Decide means to either return truthy or falsy values depending on whether the input is a Pascal's matrix, or to fix two constant values and return one for the true inputs and the other for false inputs.



This is code-golf, so try to use as few bytes as possible in the language of your choice. The shortest code in each language wins, thus I will not accept an answer.



Test cases



True



[[1, 1, 1, 1], [1, 2, 3, 4], [1, 3, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [3, 2, 1], [1, 1, 1]]
[[1, 5, 15, 35, 70], [1, 4, 10, 20, 35], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]
[[1]]
[[1, 1], [2, 1]]


False



[[2]]
[[1, 2], [2, 1]]
[[1, 1], [3, 1]]
[[1, 1, 1, 1], [1, 2, 3, 4], [1, 4, 6, 10], [1, 4, 10, 20]]
[[6, 3, 1], [1, 1, 1], [3, 2, 1]]
[[2, 2, 2, 2], [2, 4, 6, 8], [2, 6, 12, 20], [2, 8, 20, 40]]
[[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]
[[1, 5, 15, 34, 70], [1, 4, 10, 20, 34], [1, 3, 6, 10, 15], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1]]






code-golf decision-problem matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 19 at 12:16







Laikoni

















asked Mar 18 at 21:08









LaikoniLaikoni

20.2k438103




20.2k438103











  • $begingroup$
    Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
    $endgroup$
    – Kevin Cruijssen
    Mar 19 at 9:40











  • $begingroup$
    @KevinCruijssen Thanks, added.
    $endgroup$
    – Laikoni
    Mar 19 at 12:16
















  • $begingroup$
    Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
    $endgroup$
    – Kevin Cruijssen
    Mar 19 at 9:40











  • $begingroup$
    @KevinCruijssen Thanks, added.
    $endgroup$
    – Laikoni
    Mar 19 at 12:16















$begingroup$
Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
$endgroup$
– Kevin Cruijssen
Mar 19 at 9:40





$begingroup$
Suggested test case: [[40, 20, 8, 2], [20, 12, 6, 2], [8, 6, 4, 2], [2, 2, 2, 2]]. My initial answer was incorrectly truthy for this one, but correct for all of the current test cases.
$endgroup$
– Kevin Cruijssen
Mar 19 at 9:40













$begingroup$
@KevinCruijssen Thanks, added.
$endgroup$
– Laikoni
Mar 19 at 12:16




$begingroup$
@KevinCruijssen Thanks, added.
$endgroup$
– Laikoni
Mar 19 at 12:16










11 Answers
11






active

oldest

votes


















5












$begingroup$


Brachylog, 28 24 23 bytes



This feels quite long but here it is anyway



  • -4 bytes thanks to DLosc by compressing the optional flips

  • -1 bytes thanks to DLosc again by doing the partial sums in 1 go

↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁



Explanation



↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁ # Tests if this is a pascal matrix:
↔↰₁ # By trying to get a rows of 1's on top
↔ # Through optionally mirroring vertically
# Transposing
↰₁ # Through optionally mirroring vertically

ka₀ᶠ+ᵐᵐ⊆?h=₁ # and checking the following
?h=₁ # first row is a rows of 1's
k ᵐ # and for each row except the last
a₀ᶠ+ᵐ # calculate the partial sum by
a₀ᶠ # take all prefixes of the input
+ᵐ # and sum each
⊆? # => as a list is a subsequence of the rotated input


Try it online!






share|improve this answer











$endgroup$




















    4












    $begingroup$

    JavaScript (ES6), 114 bytes





    m=>[m,m,m=m.map(r=>[...r].reverse()),m].some(m=>m.reverse(p=[1]).every(r=>p=!r.some((v,x)=>v-~~p[x]-~~r[x-1])&&r))


    Try it online!






    share|improve this answer









    $endgroup$




















      3












      $begingroup$


      MATL, 17 bytes



      4:"Gas2YLG@X!X=va


      Try it online! Or verify all test cases.



      Outputs 1 for Pascal matrices, 0 otherwise.



      Explanation



      4: % Push [1 2 3 4]
      " % For each
      G % Push input: N×N
      a % 1×N vector containing 1 for matrix columns that have at least a nonzero
      % entry, and 0 otherwise. So it gives a vector containing 1 in all entries
      s % Sum. Gives N
      2YL % Pascal matrix of that size
      G % Push input
      @ % Push current iteration index
      X! % Rotate the matrix that many times in steps of 90 degress
      X= % Are they equal?
      v % Concatenate with previous accumulated result
      a % Gives 1 if at least one entry of the vector is nonzero
      % End (implicit). Display (implicit)





      share|improve this answer











      $endgroup$




















        2












        $begingroup$


        R, 104 bytes





        function(m,R=row(m)-1,y=nrow(m):1,Z=choose(R+t(R),R))any(sapply(list(Z,Z[,y],Z[y,y],Z[y,]),identical,m))


        Try it online!



        Nasty...



        Creates a canonical Pascal's matrix Z with dimensions equal to that of m, then tests if the input matrix m is identical to any of the rotations of Z.






        share|improve this answer









        $endgroup$




















          2












          $begingroup$


          Charcoal, 41 bytes



          F‹¹⌈§θ⁰≔⮌θθF‹¹⌈Eθ§ι⁰≦⮌θ⌊⭆θ⭆ι⁼λ∨¬κΣ…§θ⊖κ⊕μ


          Try it online! Link is to verbose version of code. Explanation:



          F‹¹⌈§θ⁰


          If the maximum of its first row is greater than 1,



          ≔⮌θθ


          then flip the input array.



          F‹¹⌈Eθ§ι⁰


          If the maximum of its first column is greater than 1,



          ≦⮌θ


          then mirror the input array.



          ⌊⭆θ⭆ι


          Loop over the elements of the input array and print the minimum result (i.e. the logical And of all of the results),



          ⁼λ∨¬κΣ…§θ⊖κ⊕μ


          comparing each value to 1 if it is on the first row otherwise the sum of the row above up to and including the cell above.






          share|improve this answer











          $endgroup$




















            1












            $begingroup$


            Python 2, 129 bytes





            f=lambda M,i=4:i and(set(M[0])==1and all(a+b==c for x,y in zip(M,M[1:])for a,b,c in zip(x[1:],y,y[1:]))or f(zip(*M[::-1]),i-1))


            Try it online!



            Returns True if M is a Pascal's Matrix, else 0.






            share|improve this answer









            $endgroup$




















              1












              $begingroup$


              05AB1E, 29 bytes



              ¬P≠iR}DøнP≠ií}¬PΘsü)ε`sηOQ}P*


              Try it online or verify all test cases.



              Explanation:





              ¬P≠i } # If the product of the first row of the (implicit) input-matrix is NOT 1:
              R # Reverse the order of the rows
              D # Duplicate the resulting matrix
              øнP≠i } # If the product of the first column is NOT 1:
              í # Reverse each row individually
              ¬PΘ # Check if the product of the first row is exactly 1
              * # AND
              P # And check if everything after the following map is truthy:
              sü)ε } # Map over each pair of rows:
              `sη # Get the prefixes of the first row
              O # Sum each prefix
              Q # And check if it's equal to the second row
              # (and output the result implicitly)





              share|improve this answer









              $endgroup$




















                1












                $begingroup$


                Kotlin, 269 bytes



                m:List<List<Int>>->val n=m.size
                var r=0
                var c=0
                fun f()=if(m[0][0]!=1)m[n-r-1][n-c-1]
                else if(m[n-1][0]!=1)m[r][n-c-1]
                else if(m[0][n-1]!=1)m[n-r-1][c]
                else m[r][c]
                var g=0<1
                for(l in 0..n*2-2)r=l
                c=0
                var v=1
                doif(r<n&&c<n)g=f()==v&&g
                v=v*(l-c)/++cwhile(--r>=0)
                g


                Try it online!






                share|improve this answer









                $endgroup$




















                  1












                  $begingroup$


                  Julia 0.7, 78 bytes





                  m->any(i->(n=rotr90(m,i))[1]<2&&all(cumsum(n)'[1:end-1,:]-n[2:end,:].==0),0:3)


                  Try it online!






                  share|improve this answer











                  $endgroup$




















                    1












                    $begingroup$


                    Java (JDK), 234 bytes





                    m->int l=m.length,L=l-1,p=1,s=0,S=0,e=l,E=l,d=1,D=1,i,j;if(m[0][0]>1


                    Try it online!



                    Credits



                    • -1 byte thanks to Kevin Cruijssen.





                    share|improve this answer











                    $endgroup$








                    • 1




                      $begingroup$
                      Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                      $endgroup$
                      – Kevin Cruijssen
                      2 days ago










                    • $begingroup$
                      @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                      $endgroup$
                      – Olivier Grégoire
                      2 days ago



















                    0












                    $begingroup$


                    Jelly, 22 bytes



                    Ż€Iṫ2⁼ṖaFḢ=1Ʋ
                    ,Ṛ;U$Ç€Ẹ


                    Try it online!



                    Explanation



                    Helper link, checks whether this rotation of matrix valid



                    Ż€ | prepend each row with zero
                    I | find differences within rows
                    ṫ2 | drop the first row
                    ⁼Ṗ | compare to the original matrix
                    | with the last row removed
                    a | logical and
                    FḢ=1Ʋ | top left cell is 1


                    Main link



                    ,Ṛ | copy the matrix and reverse the rows
                    ;U$ | append a copy of both of these
                    | with the columns reversed
                    ǀ | run each version of the matrix
                    | through the helper link
                    Ẹ | check if any are valid





                    share|improve this answer











                    $endgroup$












                      Your Answer





                      StackExchange.ifUsing("editor", function ()
                      return StackExchange.using("mathjaxEditing", function ()
                      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                      );
                      );
                      , "mathjax-editing");

                      StackExchange.ifUsing("editor", function ()
                      StackExchange.using("externalEditor", function ()
                      StackExchange.using("snippets", function ()
                      StackExchange.snippets.init();
                      );
                      );
                      , "code-snippets");

                      StackExchange.ready(function()
                      var channelOptions =
                      tags: "".split(" "),
                      id: "200"
                      ;
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function()
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled)
                      StackExchange.using("snippets", function()
                      createEditor();
                      );

                      else
                      createEditor();

                      );

                      function createEditor()
                      StackExchange.prepareEditor(
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: false,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: null,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader:
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      ,
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      );



                      );













                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181742%2fis-this-pascals-matrix%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown

























                      11 Answers
                      11






                      active

                      oldest

                      votes








                      11 Answers
                      11






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      5












                      $begingroup$


                      Brachylog, 28 24 23 bytes



                      This feels quite long but here it is anyway



                      • -4 bytes thanks to DLosc by compressing the optional flips

                      • -1 bytes thanks to DLosc again by doing the partial sums in 1 go

                      ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁



                      Explanation



                      ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁ # Tests if this is a pascal matrix:
                      ↔↰₁ # By trying to get a rows of 1's on top
                      ↔ # Through optionally mirroring vertically
                      # Transposing
                      ↰₁ # Through optionally mirroring vertically

                      ka₀ᶠ+ᵐᵐ⊆?h=₁ # and checking the following
                      ?h=₁ # first row is a rows of 1's
                      k ᵐ # and for each row except the last
                      a₀ᶠ+ᵐ # calculate the partial sum by
                      a₀ᶠ # take all prefixes of the input
                      +ᵐ # and sum each
                      ⊆? # => as a list is a subsequence of the rotated input


                      Try it online!






                      share|improve this answer











                      $endgroup$

















                        5












                        $begingroup$


                        Brachylog, 28 24 23 bytes



                        This feels quite long but here it is anyway



                        • -4 bytes thanks to DLosc by compressing the optional flips

                        • -1 bytes thanks to DLosc again by doing the partial sums in 1 go

                        ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁



                        Explanation



                        ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁ # Tests if this is a pascal matrix:
                        ↔↰₁ # By trying to get a rows of 1's on top
                        ↔ # Through optionally mirroring vertically
                        # Transposing
                        ↰₁ # Through optionally mirroring vertically

                        ka₀ᶠ+ᵐᵐ⊆?h=₁ # and checking the following
                        ?h=₁ # first row is a rows of 1's
                        k ᵐ # and for each row except the last
                        a₀ᶠ+ᵐ # calculate the partial sum by
                        a₀ᶠ # take all prefixes of the input
                        +ᵐ # and sum each
                        ⊆? # => as a list is a subsequence of the rotated input


                        Try it online!






                        share|improve this answer











                        $endgroup$















                          5












                          5








                          5





                          $begingroup$


                          Brachylog, 28 24 23 bytes



                          This feels quite long but here it is anyway



                          • -4 bytes thanks to DLosc by compressing the optional flips

                          • -1 bytes thanks to DLosc again by doing the partial sums in 1 go

                          ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁



                          Explanation



                          ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁ # Tests if this is a pascal matrix:
                          ↔↰₁ # By trying to get a rows of 1's on top
                          ↔ # Through optionally mirroring vertically
                          # Transposing
                          ↰₁ # Through optionally mirroring vertically

                          ka₀ᶠ+ᵐᵐ⊆?h=₁ # and checking the following
                          ?h=₁ # first row is a rows of 1's
                          k ᵐ # and for each row except the last
                          a₀ᶠ+ᵐ # calculate the partial sum by
                          a₀ᶠ # take all prefixes of the input
                          +ᵐ # and sum each
                          ⊆? # => as a list is a subsequence of the rotated input


                          Try it online!






                          share|improve this answer











                          $endgroup$




                          Brachylog, 28 24 23 bytes



                          This feels quite long but here it is anyway



                          • -4 bytes thanks to DLosc by compressing the optional flips

                          • -1 bytes thanks to DLosc again by doing the partial sums in 1 go

                          ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁



                          Explanation



                          ↔↰₁ka₀ᶠ+ᵐᵐ⊆?h=₁ # Tests if this is a pascal matrix:
                          ↔↰₁ # By trying to get a rows of 1's on top
                          ↔ # Through optionally mirroring vertically
                          # Transposing
                          ↰₁ # Through optionally mirroring vertically

                          ka₀ᶠ+ᵐᵐ⊆?h=₁ # and checking the following
                          ?h=₁ # first row is a rows of 1's
                          k ᵐ # and for each row except the last
                          a₀ᶠ+ᵐ # calculate the partial sum by
                          a₀ᶠ # take all prefixes of the input
                          +ᵐ # and sum each
                          ⊆? # => as a list is a subsequence of the rotated input


                          Try it online!







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 19 at 14:51

























                          answered Mar 18 at 22:05









                          KroppebKroppeb

                          1,366210




                          1,366210





















                              4












                              $begingroup$

                              JavaScript (ES6), 114 bytes





                              m=>[m,m,m=m.map(r=>[...r].reverse()),m].some(m=>m.reverse(p=[1]).every(r=>p=!r.some((v,x)=>v-~~p[x]-~~r[x-1])&&r))


                              Try it online!






                              share|improve this answer









                              $endgroup$

















                                4












                                $begingroup$

                                JavaScript (ES6), 114 bytes





                                m=>[m,m,m=m.map(r=>[...r].reverse()),m].some(m=>m.reverse(p=[1]).every(r=>p=!r.some((v,x)=>v-~~p[x]-~~r[x-1])&&r))


                                Try it online!






                                share|improve this answer









                                $endgroup$















                                  4












                                  4








                                  4





                                  $begingroup$

                                  JavaScript (ES6), 114 bytes





                                  m=>[m,m,m=m.map(r=>[...r].reverse()),m].some(m=>m.reverse(p=[1]).every(r=>p=!r.some((v,x)=>v-~~p[x]-~~r[x-1])&&r))


                                  Try it online!






                                  share|improve this answer









                                  $endgroup$



                                  JavaScript (ES6), 114 bytes





                                  m=>[m,m,m=m.map(r=>[...r].reverse()),m].some(m=>m.reverse(p=[1]).every(r=>p=!r.some((v,x)=>v-~~p[x]-~~r[x-1])&&r))


                                  Try it online!







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Mar 19 at 0:34









                                  ArnauldArnauld

                                  79.5k796330




                                  79.5k796330





















                                      3












                                      $begingroup$


                                      MATL, 17 bytes



                                      4:"Gas2YLG@X!X=va


                                      Try it online! Or verify all test cases.



                                      Outputs 1 for Pascal matrices, 0 otherwise.



                                      Explanation



                                      4: % Push [1 2 3 4]
                                      " % For each
                                      G % Push input: N×N
                                      a % 1×N vector containing 1 for matrix columns that have at least a nonzero
                                      % entry, and 0 otherwise. So it gives a vector containing 1 in all entries
                                      s % Sum. Gives N
                                      2YL % Pascal matrix of that size
                                      G % Push input
                                      @ % Push current iteration index
                                      X! % Rotate the matrix that many times in steps of 90 degress
                                      X= % Are they equal?
                                      v % Concatenate with previous accumulated result
                                      a % Gives 1 if at least one entry of the vector is nonzero
                                      % End (implicit). Display (implicit)





                                      share|improve this answer











                                      $endgroup$

















                                        3












                                        $begingroup$


                                        MATL, 17 bytes



                                        4:"Gas2YLG@X!X=va


                                        Try it online! Or verify all test cases.



                                        Outputs 1 for Pascal matrices, 0 otherwise.



                                        Explanation



                                        4: % Push [1 2 3 4]
                                        " % For each
                                        G % Push input: N×N
                                        a % 1×N vector containing 1 for matrix columns that have at least a nonzero
                                        % entry, and 0 otherwise. So it gives a vector containing 1 in all entries
                                        s % Sum. Gives N
                                        2YL % Pascal matrix of that size
                                        G % Push input
                                        @ % Push current iteration index
                                        X! % Rotate the matrix that many times in steps of 90 degress
                                        X= % Are they equal?
                                        v % Concatenate with previous accumulated result
                                        a % Gives 1 if at least one entry of the vector is nonzero
                                        % End (implicit). Display (implicit)





                                        share|improve this answer











                                        $endgroup$















                                          3












                                          3








                                          3





                                          $begingroup$


                                          MATL, 17 bytes



                                          4:"Gas2YLG@X!X=va


                                          Try it online! Or verify all test cases.



                                          Outputs 1 for Pascal matrices, 0 otherwise.



                                          Explanation



                                          4: % Push [1 2 3 4]
                                          " % For each
                                          G % Push input: N×N
                                          a % 1×N vector containing 1 for matrix columns that have at least a nonzero
                                          % entry, and 0 otherwise. So it gives a vector containing 1 in all entries
                                          s % Sum. Gives N
                                          2YL % Pascal matrix of that size
                                          G % Push input
                                          @ % Push current iteration index
                                          X! % Rotate the matrix that many times in steps of 90 degress
                                          X= % Are they equal?
                                          v % Concatenate with previous accumulated result
                                          a % Gives 1 if at least one entry of the vector is nonzero
                                          % End (implicit). Display (implicit)





                                          share|improve this answer











                                          $endgroup$




                                          MATL, 17 bytes



                                          4:"Gas2YLG@X!X=va


                                          Try it online! Or verify all test cases.



                                          Outputs 1 for Pascal matrices, 0 otherwise.



                                          Explanation



                                          4: % Push [1 2 3 4]
                                          " % For each
                                          G % Push input: N×N
                                          a % 1×N vector containing 1 for matrix columns that have at least a nonzero
                                          % entry, and 0 otherwise. So it gives a vector containing 1 in all entries
                                          s % Sum. Gives N
                                          2YL % Pascal matrix of that size
                                          G % Push input
                                          @ % Push current iteration index
                                          X! % Rotate the matrix that many times in steps of 90 degress
                                          X= % Are they equal?
                                          v % Concatenate with previous accumulated result
                                          a % Gives 1 if at least one entry of the vector is nonzero
                                          % End (implicit). Display (implicit)






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Mar 19 at 15:08

























                                          answered Mar 19 at 9:41









                                          Luis MendoLuis Mendo

                                          74.9k888291




                                          74.9k888291





















                                              2












                                              $begingroup$


                                              R, 104 bytes





                                              function(m,R=row(m)-1,y=nrow(m):1,Z=choose(R+t(R),R))any(sapply(list(Z,Z[,y],Z[y,y],Z[y,]),identical,m))


                                              Try it online!



                                              Nasty...



                                              Creates a canonical Pascal's matrix Z with dimensions equal to that of m, then tests if the input matrix m is identical to any of the rotations of Z.






                                              share|improve this answer









                                              $endgroup$

















                                                2












                                                $begingroup$


                                                R, 104 bytes





                                                function(m,R=row(m)-1,y=nrow(m):1,Z=choose(R+t(R),R))any(sapply(list(Z,Z[,y],Z[y,y],Z[y,]),identical,m))


                                                Try it online!



                                                Nasty...



                                                Creates a canonical Pascal's matrix Z with dimensions equal to that of m, then tests if the input matrix m is identical to any of the rotations of Z.






                                                share|improve this answer









                                                $endgroup$















                                                  2












                                                  2








                                                  2





                                                  $begingroup$


                                                  R, 104 bytes





                                                  function(m,R=row(m)-1,y=nrow(m):1,Z=choose(R+t(R),R))any(sapply(list(Z,Z[,y],Z[y,y],Z[y,]),identical,m))


                                                  Try it online!



                                                  Nasty...



                                                  Creates a canonical Pascal's matrix Z with dimensions equal to that of m, then tests if the input matrix m is identical to any of the rotations of Z.






                                                  share|improve this answer









                                                  $endgroup$




                                                  R, 104 bytes





                                                  function(m,R=row(m)-1,y=nrow(m):1,Z=choose(R+t(R),R))any(sapply(list(Z,Z[,y],Z[y,y],Z[y,]),identical,m))


                                                  Try it online!



                                                  Nasty...



                                                  Creates a canonical Pascal's matrix Z with dimensions equal to that of m, then tests if the input matrix m is identical to any of the rotations of Z.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Mar 19 at 16:30









                                                  GiuseppeGiuseppe

                                                  17k31052




                                                  17k31052





















                                                      2












                                                      $begingroup$


                                                      Charcoal, 41 bytes



                                                      F‹¹⌈§θ⁰≔⮌θθF‹¹⌈Eθ§ι⁰≦⮌θ⌊⭆θ⭆ι⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                      Try it online! Link is to verbose version of code. Explanation:



                                                      F‹¹⌈§θ⁰


                                                      If the maximum of its first row is greater than 1,



                                                      ≔⮌θθ


                                                      then flip the input array.



                                                      F‹¹⌈Eθ§ι⁰


                                                      If the maximum of its first column is greater than 1,



                                                      ≦⮌θ


                                                      then mirror the input array.



                                                      ⌊⭆θ⭆ι


                                                      Loop over the elements of the input array and print the minimum result (i.e. the logical And of all of the results),



                                                      ⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                      comparing each value to 1 if it is on the first row otherwise the sum of the row above up to and including the cell above.






                                                      share|improve this answer











                                                      $endgroup$

















                                                        2












                                                        $begingroup$


                                                        Charcoal, 41 bytes



                                                        F‹¹⌈§θ⁰≔⮌θθF‹¹⌈Eθ§ι⁰≦⮌θ⌊⭆θ⭆ι⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                        Try it online! Link is to verbose version of code. Explanation:



                                                        F‹¹⌈§θ⁰


                                                        If the maximum of its first row is greater than 1,



                                                        ≔⮌θθ


                                                        then flip the input array.



                                                        F‹¹⌈Eθ§ι⁰


                                                        If the maximum of its first column is greater than 1,



                                                        ≦⮌θ


                                                        then mirror the input array.



                                                        ⌊⭆θ⭆ι


                                                        Loop over the elements of the input array and print the minimum result (i.e. the logical And of all of the results),



                                                        ⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                        comparing each value to 1 if it is on the first row otherwise the sum of the row above up to and including the cell above.






                                                        share|improve this answer











                                                        $endgroup$















                                                          2












                                                          2








                                                          2





                                                          $begingroup$


                                                          Charcoal, 41 bytes



                                                          F‹¹⌈§θ⁰≔⮌θθF‹¹⌈Eθ§ι⁰≦⮌θ⌊⭆θ⭆ι⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                          Try it online! Link is to verbose version of code. Explanation:



                                                          F‹¹⌈§θ⁰


                                                          If the maximum of its first row is greater than 1,



                                                          ≔⮌θθ


                                                          then flip the input array.



                                                          F‹¹⌈Eθ§ι⁰


                                                          If the maximum of its first column is greater than 1,



                                                          ≦⮌θ


                                                          then mirror the input array.



                                                          ⌊⭆θ⭆ι


                                                          Loop over the elements of the input array and print the minimum result (i.e. the logical And of all of the results),



                                                          ⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                          comparing each value to 1 if it is on the first row otherwise the sum of the row above up to and including the cell above.






                                                          share|improve this answer











                                                          $endgroup$




                                                          Charcoal, 41 bytes



                                                          F‹¹⌈§θ⁰≔⮌θθF‹¹⌈Eθ§ι⁰≦⮌θ⌊⭆θ⭆ι⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                          Try it online! Link is to verbose version of code. Explanation:



                                                          F‹¹⌈§θ⁰


                                                          If the maximum of its first row is greater than 1,



                                                          ≔⮌θθ


                                                          then flip the input array.



                                                          F‹¹⌈Eθ§ι⁰


                                                          If the maximum of its first column is greater than 1,



                                                          ≦⮌θ


                                                          then mirror the input array.



                                                          ⌊⭆θ⭆ι


                                                          Loop over the elements of the input array and print the minimum result (i.e. the logical And of all of the results),



                                                          ⁼λ∨¬κΣ…§θ⊖κ⊕μ


                                                          comparing each value to 1 if it is on the first row otherwise the sum of the row above up to and including the cell above.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited 2 days ago

























                                                          answered Mar 18 at 23:46









                                                          NeilNeil

                                                          82k745178




                                                          82k745178





















                                                              1












                                                              $begingroup$


                                                              Python 2, 129 bytes





                                                              f=lambda M,i=4:i and(set(M[0])==1and all(a+b==c for x,y in zip(M,M[1:])for a,b,c in zip(x[1:],y,y[1:]))or f(zip(*M[::-1]),i-1))


                                                              Try it online!



                                                              Returns True if M is a Pascal's Matrix, else 0.






                                                              share|improve this answer









                                                              $endgroup$

















                                                                1












                                                                $begingroup$


                                                                Python 2, 129 bytes





                                                                f=lambda M,i=4:i and(set(M[0])==1and all(a+b==c for x,y in zip(M,M[1:])for a,b,c in zip(x[1:],y,y[1:]))or f(zip(*M[::-1]),i-1))


                                                                Try it online!



                                                                Returns True if M is a Pascal's Matrix, else 0.






                                                                share|improve this answer









                                                                $endgroup$















                                                                  1












                                                                  1








                                                                  1





                                                                  $begingroup$


                                                                  Python 2, 129 bytes





                                                                  f=lambda M,i=4:i and(set(M[0])==1and all(a+b==c for x,y in zip(M,M[1:])for a,b,c in zip(x[1:],y,y[1:]))or f(zip(*M[::-1]),i-1))


                                                                  Try it online!



                                                                  Returns True if M is a Pascal's Matrix, else 0.






                                                                  share|improve this answer









                                                                  $endgroup$




                                                                  Python 2, 129 bytes





                                                                  f=lambda M,i=4:i and(set(M[0])==1and all(a+b==c for x,y in zip(M,M[1:])for a,b,c in zip(x[1:],y,y[1:]))or f(zip(*M[::-1]),i-1))


                                                                  Try it online!



                                                                  Returns True if M is a Pascal's Matrix, else 0.







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Mar 19 at 6:00









                                                                  Chas BrownChas Brown

                                                                  5,0641523




                                                                  5,0641523





















                                                                      1












                                                                      $begingroup$


                                                                      05AB1E, 29 bytes



                                                                      ¬P≠iR}DøнP≠ií}¬PΘsü)ε`sηOQ}P*


                                                                      Try it online or verify all test cases.



                                                                      Explanation:





                                                                      ¬P≠i } # If the product of the first row of the (implicit) input-matrix is NOT 1:
                                                                      R # Reverse the order of the rows
                                                                      D # Duplicate the resulting matrix
                                                                      øнP≠i } # If the product of the first column is NOT 1:
                                                                      í # Reverse each row individually
                                                                      ¬PΘ # Check if the product of the first row is exactly 1
                                                                      * # AND
                                                                      P # And check if everything after the following map is truthy:
                                                                      sü)ε } # Map over each pair of rows:
                                                                      `sη # Get the prefixes of the first row
                                                                      O # Sum each prefix
                                                                      Q # And check if it's equal to the second row
                                                                      # (and output the result implicitly)





                                                                      share|improve this answer









                                                                      $endgroup$

















                                                                        1












                                                                        $begingroup$


                                                                        05AB1E, 29 bytes



                                                                        ¬P≠iR}DøнP≠ií}¬PΘsü)ε`sηOQ}P*


                                                                        Try it online or verify all test cases.



                                                                        Explanation:





                                                                        ¬P≠i } # If the product of the first row of the (implicit) input-matrix is NOT 1:
                                                                        R # Reverse the order of the rows
                                                                        D # Duplicate the resulting matrix
                                                                        øнP≠i } # If the product of the first column is NOT 1:
                                                                        í # Reverse each row individually
                                                                        ¬PΘ # Check if the product of the first row is exactly 1
                                                                        * # AND
                                                                        P # And check if everything after the following map is truthy:
                                                                        sü)ε } # Map over each pair of rows:
                                                                        `sη # Get the prefixes of the first row
                                                                        O # Sum each prefix
                                                                        Q # And check if it's equal to the second row
                                                                        # (and output the result implicitly)





                                                                        share|improve this answer









                                                                        $endgroup$















                                                                          1












                                                                          1








                                                                          1





                                                                          $begingroup$


                                                                          05AB1E, 29 bytes



                                                                          ¬P≠iR}DøнP≠ií}¬PΘsü)ε`sηOQ}P*


                                                                          Try it online or verify all test cases.



                                                                          Explanation:





                                                                          ¬P≠i } # If the product of the first row of the (implicit) input-matrix is NOT 1:
                                                                          R # Reverse the order of the rows
                                                                          D # Duplicate the resulting matrix
                                                                          øнP≠i } # If the product of the first column is NOT 1:
                                                                          í # Reverse each row individually
                                                                          ¬PΘ # Check if the product of the first row is exactly 1
                                                                          * # AND
                                                                          P # And check if everything after the following map is truthy:
                                                                          sü)ε } # Map over each pair of rows:
                                                                          `sη # Get the prefixes of the first row
                                                                          O # Sum each prefix
                                                                          Q # And check if it's equal to the second row
                                                                          # (and output the result implicitly)





                                                                          share|improve this answer









                                                                          $endgroup$




                                                                          05AB1E, 29 bytes



                                                                          ¬P≠iR}DøнP≠ií}¬PΘsü)ε`sηOQ}P*


                                                                          Try it online or verify all test cases.



                                                                          Explanation:





                                                                          ¬P≠i } # If the product of the first row of the (implicit) input-matrix is NOT 1:
                                                                          R # Reverse the order of the rows
                                                                          D # Duplicate the resulting matrix
                                                                          øнP≠i } # If the product of the first column is NOT 1:
                                                                          í # Reverse each row individually
                                                                          ¬PΘ # Check if the product of the first row is exactly 1
                                                                          * # AND
                                                                          P # And check if everything after the following map is truthy:
                                                                          sü)ε } # Map over each pair of rows:
                                                                          `sη # Get the prefixes of the first row
                                                                          O # Sum each prefix
                                                                          Q # And check if it's equal to the second row
                                                                          # (and output the result implicitly)






                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Mar 19 at 9:37









                                                                          Kevin CruijssenKevin Cruijssen

                                                                          41.3k567212




                                                                          41.3k567212





















                                                                              1












                                                                              $begingroup$


                                                                              Kotlin, 269 bytes



                                                                              m:List<List<Int>>->val n=m.size
                                                                              var r=0
                                                                              var c=0
                                                                              fun f()=if(m[0][0]!=1)m[n-r-1][n-c-1]
                                                                              else if(m[n-1][0]!=1)m[r][n-c-1]
                                                                              else if(m[0][n-1]!=1)m[n-r-1][c]
                                                                              else m[r][c]
                                                                              var g=0<1
                                                                              for(l in 0..n*2-2)r=l
                                                                              c=0
                                                                              var v=1
                                                                              doif(r<n&&c<n)g=f()==v&&g
                                                                              v=v*(l-c)/++cwhile(--r>=0)
                                                                              g


                                                                              Try it online!






                                                                              share|improve this answer









                                                                              $endgroup$

















                                                                                1












                                                                                $begingroup$


                                                                                Kotlin, 269 bytes



                                                                                m:List<List<Int>>->val n=m.size
                                                                                var r=0
                                                                                var c=0
                                                                                fun f()=if(m[0][0]!=1)m[n-r-1][n-c-1]
                                                                                else if(m[n-1][0]!=1)m[r][n-c-1]
                                                                                else if(m[0][n-1]!=1)m[n-r-1][c]
                                                                                else m[r][c]
                                                                                var g=0<1
                                                                                for(l in 0..n*2-2)r=l
                                                                                c=0
                                                                                var v=1
                                                                                doif(r<n&&c<n)g=f()==v&&g
                                                                                v=v*(l-c)/++cwhile(--r>=0)
                                                                                g


                                                                                Try it online!






                                                                                share|improve this answer









                                                                                $endgroup$















                                                                                  1












                                                                                  1








                                                                                  1





                                                                                  $begingroup$


                                                                                  Kotlin, 269 bytes



                                                                                  m:List<List<Int>>->val n=m.size
                                                                                  var r=0
                                                                                  var c=0
                                                                                  fun f()=if(m[0][0]!=1)m[n-r-1][n-c-1]
                                                                                  else if(m[n-1][0]!=1)m[r][n-c-1]
                                                                                  else if(m[0][n-1]!=1)m[n-r-1][c]
                                                                                  else m[r][c]
                                                                                  var g=0<1
                                                                                  for(l in 0..n*2-2)r=l
                                                                                  c=0
                                                                                  var v=1
                                                                                  doif(r<n&&c<n)g=f()==v&&g
                                                                                  v=v*(l-c)/++cwhile(--r>=0)
                                                                                  g


                                                                                  Try it online!






                                                                                  share|improve this answer









                                                                                  $endgroup$




                                                                                  Kotlin, 269 bytes



                                                                                  m:List<List<Int>>->val n=m.size
                                                                                  var r=0
                                                                                  var c=0
                                                                                  fun f()=if(m[0][0]!=1)m[n-r-1][n-c-1]
                                                                                  else if(m[n-1][0]!=1)m[r][n-c-1]
                                                                                  else if(m[0][n-1]!=1)m[n-r-1][c]
                                                                                  else m[r][c]
                                                                                  var g=0<1
                                                                                  for(l in 0..n*2-2)r=l
                                                                                  c=0
                                                                                  var v=1
                                                                                  doif(r<n&&c<n)g=f()==v&&g
                                                                                  v=v*(l-c)/++cwhile(--r>=0)
                                                                                  g


                                                                                  Try it online!







                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Mar 20 at 2:24









                                                                                  JohnWellsJohnWells

                                                                                  5416




                                                                                  5416





















                                                                                      1












                                                                                      $begingroup$


                                                                                      Julia 0.7, 78 bytes





                                                                                      m->any(i->(n=rotr90(m,i))[1]<2&&all(cumsum(n)'[1:end-1,:]-n[2:end,:].==0),0:3)


                                                                                      Try it online!






                                                                                      share|improve this answer











                                                                                      $endgroup$

















                                                                                        1












                                                                                        $begingroup$


                                                                                        Julia 0.7, 78 bytes





                                                                                        m->any(i->(n=rotr90(m,i))[1]<2&&all(cumsum(n)'[1:end-1,:]-n[2:end,:].==0),0:3)


                                                                                        Try it online!






                                                                                        share|improve this answer











                                                                                        $endgroup$















                                                                                          1












                                                                                          1








                                                                                          1





                                                                                          $begingroup$


                                                                                          Julia 0.7, 78 bytes





                                                                                          m->any(i->(n=rotr90(m,i))[1]<2&&all(cumsum(n)'[1:end-1,:]-n[2:end,:].==0),0:3)


                                                                                          Try it online!






                                                                                          share|improve this answer











                                                                                          $endgroup$




                                                                                          Julia 0.7, 78 bytes





                                                                                          m->any(i->(n=rotr90(m,i))[1]<2&&all(cumsum(n)'[1:end-1,:]-n[2:end,:].==0),0:3)


                                                                                          Try it online!







                                                                                          share|improve this answer














                                                                                          share|improve this answer



                                                                                          share|improve this answer








                                                                                          edited 2 days ago

























                                                                                          answered Mar 19 at 9:29









                                                                                          Kirill L.Kirill L.

                                                                                          5,6831525




                                                                                          5,6831525





















                                                                                              1












                                                                                              $begingroup$


                                                                                              Java (JDK), 234 bytes





                                                                                              m->int l=m.length,L=l-1,p=1,s=0,S=0,e=l,E=l,d=1,D=1,i,j;if(m[0][0]>1


                                                                                              Try it online!



                                                                                              Credits



                                                                                              • -1 byte thanks to Kevin Cruijssen.





                                                                                              share|improve this answer











                                                                                              $endgroup$








                                                                                              • 1




                                                                                                $begingroup$
                                                                                                Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                2 days ago










                                                                                              • $begingroup$
                                                                                                @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                                $endgroup$
                                                                                                – Olivier Grégoire
                                                                                                2 days ago
















                                                                                              1












                                                                                              $begingroup$


                                                                                              Java (JDK), 234 bytes





                                                                                              m->int l=m.length,L=l-1,p=1,s=0,S=0,e=l,E=l,d=1,D=1,i,j;if(m[0][0]>1


                                                                                              Try it online!



                                                                                              Credits



                                                                                              • -1 byte thanks to Kevin Cruijssen.





                                                                                              share|improve this answer











                                                                                              $endgroup$








                                                                                              • 1




                                                                                                $begingroup$
                                                                                                Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                2 days ago










                                                                                              • $begingroup$
                                                                                                @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                                $endgroup$
                                                                                                – Olivier Grégoire
                                                                                                2 days ago














                                                                                              1












                                                                                              1








                                                                                              1





                                                                                              $begingroup$


                                                                                              Java (JDK), 234 bytes





                                                                                              m->int l=m.length,L=l-1,p=1,s=0,S=0,e=l,E=l,d=1,D=1,i,j;if(m[0][0]>1


                                                                                              Try it online!



                                                                                              Credits



                                                                                              • -1 byte thanks to Kevin Cruijssen.





                                                                                              share|improve this answer











                                                                                              $endgroup$




                                                                                              Java (JDK), 234 bytes





                                                                                              m->int l=m.length,L=l-1,p=1,s=0,S=0,e=l,E=l,d=1,D=1,i,j;if(m[0][0]>1


                                                                                              Try it online!



                                                                                              Credits



                                                                                              • -1 byte thanks to Kevin Cruijssen.






                                                                                              share|improve this answer














                                                                                              share|improve this answer



                                                                                              share|improve this answer








                                                                                              edited 2 days ago

























                                                                                              answered Mar 19 at 16:01









                                                                                              Olivier GrégoireOlivier Grégoire

                                                                                              9,31511944




                                                                                              9,31511944







                                                                                              • 1




                                                                                                $begingroup$
                                                                                                Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                2 days ago










                                                                                              • $begingroup$
                                                                                                @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                                $endgroup$
                                                                                                – Olivier Grégoire
                                                                                                2 days ago













                                                                                              • 1




                                                                                                $begingroup$
                                                                                                Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                2 days ago










                                                                                              • $begingroup$
                                                                                                @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                                $endgroup$
                                                                                                – Olivier Grégoire
                                                                                                2 days ago








                                                                                              1




                                                                                              1




                                                                                              $begingroup$
                                                                                              Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                              $endgroup$
                                                                                              – Kevin Cruijssen
                                                                                              2 days ago




                                                                                              $begingroup$
                                                                                              Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                              $endgroup$
                                                                                              – Kevin Cruijssen
                                                                                              2 days ago












                                                                                              $begingroup$
                                                                                              @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                              $endgroup$
                                                                                              – Olivier Grégoire
                                                                                              2 days ago





                                                                                              $begingroup$
                                                                                              @KevinCruijssen if you know a better algorithm I take it! But the rotation is the cause for all the variables. Some languages can handle them in 1-2 bytes, in Java, you have to think the code around them. The core algorithm is actually pretty short: m->j<1?m[i][j]<2:m[i][j]==m[i-1][j]+m[i][j-1])?p:0;return p>0; (122 bytes)
                                                                                              $endgroup$
                                                                                              – Olivier Grégoire
                                                                                              2 days ago












                                                                                              0












                                                                                              $begingroup$


                                                                                              Jelly, 22 bytes



                                                                                              Ż€Iṫ2⁼ṖaFḢ=1Ʋ
                                                                                              ,Ṛ;U$Ç€Ẹ


                                                                                              Try it online!



                                                                                              Explanation



                                                                                              Helper link, checks whether this rotation of matrix valid



                                                                                              Ż€ | prepend each row with zero
                                                                                              I | find differences within rows
                                                                                              ṫ2 | drop the first row
                                                                                              ⁼Ṗ | compare to the original matrix
                                                                                              | with the last row removed
                                                                                              a | logical and
                                                                                              FḢ=1Ʋ | top left cell is 1


                                                                                              Main link



                                                                                              ,Ṛ | copy the matrix and reverse the rows
                                                                                              ;U$ | append a copy of both of these
                                                                                              | with the columns reversed
                                                                                              ǀ | run each version of the matrix
                                                                                              | through the helper link
                                                                                              Ẹ | check if any are valid





                                                                                              share|improve this answer











                                                                                              $endgroup$

















                                                                                                0












                                                                                                $begingroup$


                                                                                                Jelly, 22 bytes



                                                                                                Ż€Iṫ2⁼ṖaFḢ=1Ʋ
                                                                                                ,Ṛ;U$Ç€Ẹ


                                                                                                Try it online!



                                                                                                Explanation



                                                                                                Helper link, checks whether this rotation of matrix valid



                                                                                                Ż€ | prepend each row with zero
                                                                                                I | find differences within rows
                                                                                                ṫ2 | drop the first row
                                                                                                ⁼Ṗ | compare to the original matrix
                                                                                                | with the last row removed
                                                                                                a | logical and
                                                                                                FḢ=1Ʋ | top left cell is 1


                                                                                                Main link



                                                                                                ,Ṛ | copy the matrix and reverse the rows
                                                                                                ;U$ | append a copy of both of these
                                                                                                | with the columns reversed
                                                                                                ǀ | run each version of the matrix
                                                                                                | through the helper link
                                                                                                Ẹ | check if any are valid





                                                                                                share|improve this answer











                                                                                                $endgroup$















                                                                                                  0












                                                                                                  0








                                                                                                  0





                                                                                                  $begingroup$


                                                                                                  Jelly, 22 bytes



                                                                                                  Ż€Iṫ2⁼ṖaFḢ=1Ʋ
                                                                                                  ,Ṛ;U$Ç€Ẹ


                                                                                                  Try it online!



                                                                                                  Explanation



                                                                                                  Helper link, checks whether this rotation of matrix valid



                                                                                                  Ż€ | prepend each row with zero
                                                                                                  I | find differences within rows
                                                                                                  ṫ2 | drop the first row
                                                                                                  ⁼Ṗ | compare to the original matrix
                                                                                                  | with the last row removed
                                                                                                  a | logical and
                                                                                                  FḢ=1Ʋ | top left cell is 1


                                                                                                  Main link



                                                                                                  ,Ṛ | copy the matrix and reverse the rows
                                                                                                  ;U$ | append a copy of both of these
                                                                                                  | with the columns reversed
                                                                                                  ǀ | run each version of the matrix
                                                                                                  | through the helper link
                                                                                                  Ẹ | check if any are valid





                                                                                                  share|improve this answer











                                                                                                  $endgroup$




                                                                                                  Jelly, 22 bytes



                                                                                                  Ż€Iṫ2⁼ṖaFḢ=1Ʋ
                                                                                                  ,Ṛ;U$Ç€Ẹ


                                                                                                  Try it online!



                                                                                                  Explanation



                                                                                                  Helper link, checks whether this rotation of matrix valid



                                                                                                  Ż€ | prepend each row with zero
                                                                                                  I | find differences within rows
                                                                                                  ṫ2 | drop the first row
                                                                                                  ⁼Ṗ | compare to the original matrix
                                                                                                  | with the last row removed
                                                                                                  a | logical and
                                                                                                  FḢ=1Ʋ | top left cell is 1


                                                                                                  Main link



                                                                                                  ,Ṛ | copy the matrix and reverse the rows
                                                                                                  ;U$ | append a copy of both of these
                                                                                                  | with the columns reversed
                                                                                                  ǀ | run each version of the matrix
                                                                                                  | through the helper link
                                                                                                  Ẹ | check if any are valid






                                                                                                  share|improve this answer














                                                                                                  share|improve this answer



                                                                                                  share|improve this answer








                                                                                                  edited 2 days ago

























                                                                                                  answered 2 days ago









                                                                                                  Nick KennedyNick Kennedy

                                                                                                  89137




                                                                                                  89137



























                                                                                                      draft saved

                                                                                                      draft discarded
















































                                                                                                      If this is an answer to a challenge…



                                                                                                      • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                      • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                        Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                      • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                                                                                      More generally…



                                                                                                      • …Please make sure to answer the question and provide sufficient detail.


                                                                                                      • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                                                                                      draft saved


                                                                                                      draft discarded














                                                                                                      StackExchange.ready(
                                                                                                      function ()
                                                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181742%2fis-this-pascals-matrix%23new-answer', 'question_page');

                                                                                                      );

                                                                                                      Post as a guest















                                                                                                      Required, but never shown





















































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown

































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown







                                                                                                      Popular posts from this blog

                                                                                                      Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

                                                                                                      Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

                                                                                                      Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?