Is this Pascal's Matrix? The Next CEO of Stack OverflowDiamondize 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

How did people program for Consoles with multiple CPUs?

Science fiction short story involving a paper written by a schizophrenic

Is it safe to use c_str() on a temporary string?

How to make a software documentation "officially" citable?

What's the Pac-Man-like video game seen in the movie "Joysticks"?

If the heap is initialized for security, then why is the stack uninitialized?

What is the difference between Sanyaas and Vairagya?

Opposite of a diet

Why do remote companies require working in the US?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How do I go from 300 unfinished/half written blog posts, to published posts?

Why is there a PLL in CPU?

Inappropriate reference requests from Journal reviewers

What is the difference between "behavior" and "behaviour"?

How do I construct this japanese bowl?

Path-continuity and the Axiom of Choice

How to Reset Passwords on Multiple Websites Easily?

Unreliable Magic - Is it worth it?

Should I tutor a student who I know has cheated on their homework?

Apart from "berlinern", do any other German dialects have a corresponding verb?

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Rotate a column

Why do we use the plural of movies in this phrase "We went to the movies last night."?

Why did we only see the N-1 starfighters in one film?



Is this Pascal's Matrix?



The Next CEO of Stack OverflowDiamondize 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.3k439103




20.3k439103











  • $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$




















      4












      $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
                      Mar 20 at 14:26










                    • $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
                      Mar 20 at 15:41



















                    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,396210




                          1,396210





















                              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.9k797330




                                  79.9k797330





















                                      4












                                      $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$

















                                        4












                                        $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$















                                          4












                                          4








                                          4





                                          $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

                                          75.1k888291




                                          75.1k888291





















                                              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

                                                  17.2k31152




                                                  17.2k31152





















                                                      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 Mar 20 at 9:58

























                                                          answered Mar 18 at 23:46









                                                          NeilNeil

                                                          82.1k745178




                                                          82.1k745178





















                                                              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.8k568217




                                                                          41.8k568217





















                                                                              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

                                                                                  54116




                                                                                  54116





















                                                                                      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 Mar 20 at 8:42

























                                                                                          answered Mar 19 at 9:29









                                                                                          Kirill L.Kirill L.

                                                                                          5,9131526




                                                                                          5,9131526





















                                                                                              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
                                                                                                Mar 20 at 14:26










                                                                                              • $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
                                                                                                Mar 20 at 15:41
















                                                                                              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
                                                                                                Mar 20 at 14:26










                                                                                              • $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
                                                                                                Mar 20 at 15:41














                                                                                              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 Mar 20 at 15:08

























                                                                                              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
                                                                                                Mar 20 at 14:26










                                                                                              • $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
                                                                                                Mar 20 at 15:41













                                                                                              • 1




                                                                                                $begingroup$
                                                                                                Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                Mar 20 at 14:26










                                                                                              • $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
                                                                                                Mar 20 at 15:41








                                                                                              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
                                                                                              Mar 20 at 14:26




                                                                                              $begingroup$
                                                                                              Nice answer, but dang, loads of variables. ;) Oh, and -1: i==s||j==S to i==s|j==S.
                                                                                              $endgroup$
                                                                                              – Kevin Cruijssen
                                                                                              Mar 20 at 14:26












                                                                                              $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
                                                                                              Mar 20 at 15:41





                                                                                              $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
                                                                                              Mar 20 at 15:41












                                                                                              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 Mar 20 at 15:16

























                                                                                                  answered Mar 20 at 14:08









                                                                                                  Nick KennedyNick Kennedy

                                                                                                  1,09648




                                                                                                  1,09648



























                                                                                                      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

                                                                                                      Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

                                                                                                      Masuk log Menu navigasi

                                                                                                      อาณาจักร (ชีววิทยา) ดูเพิ่ม อ้างอิง รายการเลือกการนำทาง10.1086/39456810.5962/bhl.title.447410.1126/science.163.3863.150576276010.1007/BF01796092408502"Phylogenetic structure of the prokaryotic domain: the primary kingdoms"10.1073/pnas.74.11.5088432104270744"Towards a natural system of organisms: proposal for the domains Archaea, Bacteria, and Eucarya"1990PNAS...87.4576W10.1073/pnas.87.12.4576541592112744PubMedJump the queueexpand by handPubMedJump the queueexpand by handPubMedJump the queueexpand by hand"A revised six-kingdom system of life"10.1111/j.1469-185X.1998.tb00030.x9809012"Only six kingdoms of life"10.1098/rspb.2004.2705169172415306349"Kingdoms Protozoa and Chromista and the eozoan root of the eukaryotic tree"10.1098/rsbl.2009.0948288006020031978เพิ่มข้อมูล