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 Revisions

3 of 4
Fixed
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#05AB1E, 25 bytes

ZÌLsgãε©.Γü+} ̈®š.S* ̃O_}OΘ

Takes the pyramid layers in upside down order, base to tip (i.e. [[0,0,0,1],[0,2,0],[0,0],[10]]).

Also, there seems to be a bug somewhere in 05AB1E with inside a map.. The ©...®š should just be ...yš for -1 byte..

Try it online or verify a few more test cases.

A minor equal-bytes alternative for ©.ΓüO}®š could be [Ðg#üO}\): Try it online.

Explanation:

Z # Get the flattened maximum of the (implicit) input (without popping)
 Ì # Increase it by 2
 L # Create a list in the range [1, max+2]
 sg # Swap to get the input again, and get the length (amount of layers)
 ã # Create a cartesian product of this list repeated that many times
ε # Map each inner list to:
 © # Store it in variable `®` (without popping)
 .Γ # Collect all results until the following doesn't change anymore:
 ü # Get the pairwise:
 + # Sums
 }®š # After we've collected all, prepend the original list `®`
 .S # Now compare this potential pyramid with the (implicit) input-pyramid
 # (-1 if a<b; 0 if a==b; 1 if a>b)
 * # Multiply that with the (implicit) input-pyramid
 ̃O # Then take the flattened sum
 _ # And check that this sum equals 0 (1 if truhy; 0 if falsey)
}O # After the map, take the sum to get the amount of truthy values
 Θ # And trutify it (== 1), since we must output distinct values instead of truthy/falsey
 # (after which the result is output implicitly)
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

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