Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

improvement
Source Link
Kroppeb
  • 1.8k
  • 10
  • 11

Brachylog, 24(削除) 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

-4 bytes thanks to DLosc{|↔}\↰1{k{a0f+m}m⊆?h=1}

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩mk{a0f+m}m⊆?h=1} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩mk{a0f+m}m⊆?h=1} # and checking the following
 h=1  ?h=1 # first row is a rows of 1's
 k{ s2f  }m # and for each 2 rows whichrow followexcept eachthe otherlast
 a0f+m ⟨a0f+m⟩m # # the 2nd iscalculate the partial sums of thesum 1stby
 a0f a0f # take all prefixes of the 1stinput
 +m +m # whichand ifsum summedeach
 are ⊆? # => as a list is a subsequence of the 2ndrotated input

Try it online! Try it online!

Brachylog, 24 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1  # first row is a rows of 1's
 s2f  # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

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

{|↔}\↰1{k{a0f+m}m⊆?h=1}

Explanation

{|↔}\↰1{k{a0f+m}m⊆?h=1} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {k{a0f+m}m⊆?h=1} # and checking the following
 ?h=1 # first row is a rows of 1's
 k{ }m # and for each row except the last
 a0f+m # calculate the partial sum by
 a0f # take all prefixes of the input
 +m # and sum each
  ⊆? # => as a list is a subsequence of the rotated input

Try it online!

edited body
Source Link
Fatalize
  • 39.6k
  • 5
  • 73
  • 165

Brachylog, 2824 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 # first row is a rows of 1's
 s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

Brachylog, 28 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 # first row is a rows of 1's
 s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

Brachylog, 24 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
{|↔}\↰1 # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1 # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 # first row is a rows of 1's
 s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

Improvement to score
Source Link
Kroppeb
  • 1.8k
  • 10
  • 11

Brachylog, 28 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

⟨≡∋↔⟩\⟨≡∋↔⟩{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

⟨≡∋↔⟩\⟨≡∋↔⟩{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
⟨≡∋↔⟩\⟨≡∋↔⟩{|↔}\↰1  # By trying to get a rows of 1's on top
⟨≡∋↔⟩{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ⟨≡∋↔⟩↰1  # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 h=1 # first row is a rows of 1's
 s2f s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f a0f # take all prefixes of the 1st
 +m +m # which if summed are the 2nd

Try it online! Try it online!

Brachylog, 28 bytes

This feels quite long but here it is anyway

⟨≡∋↔⟩\⟨≡∋↔⟩{h=1&s2f⟨a0f+m⟩m}

Explanation

⟨≡∋↔⟩\⟨≡∋↔⟩{h=1&s2f⟨a0f+m⟩m} # 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
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 # first row is a rows of 1's
 s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

Brachylog, 28 bytes

This feels quite long but here it is anyway

-4 bytes thanks to DLosc

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m}

Explanation

{|↔}\↰1{h=1&s2f⟨a0f+m⟩m} # Tests if this is a pascal matrix:
{|↔}\↰1  # By trying to get a rows of 1's on top
{|↔} # Through optionally mirroring vertically
 \ # Transposing
 ↰1  # Through optionally mirroring vertically
 {h=1&s2f⟨a0f+m⟩m} # and checking the following
 h=1 # first row is a rows of 1's
 s2f # and for each 2 rows which follow each other
 ⟨a0f+m⟩m # the 2nd is the partial sums of the 1st
 a0f # take all prefixes of the 1st
 +m # which if summed are the 2nd

Try it online!

Typos
Source Link
Kroppeb
  • 1.8k
  • 10
  • 11
Loading
Source Link
Kroppeb
  • 1.8k
  • 10
  • 11
Loading

AltStyle によって変換されたページ (->オリジナル) /