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

Commonmark migration
Source Link

#05AB1E , 25 bytes

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)

#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)

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)
Post Undeleted by Kevin Cruijssen
Fixed
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#05AB1E, 2325 bytes

Z>Lsgãε©ZÌLsgãε©.Γü+}®š% ̃O_ ̈®š.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 Try it online or verify a few more test cases verify a few more test cases.

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

Explanation:

Z # Get the flattened maximum of the (implicit) input (without popping)
 >Ì # Increase it by 12
 L # Create a list in the range [1, max+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 modulocompare this potential pyramid with the (implicit) input-pyramid
  ̃O # Take(-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)

#05AB1E, 23 bytes

Z>Lsgãε©.Γü+}®š% ̃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 1
 L # Create a list in the range [1, max+1]
 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 `®`
 %  # Now modulo this potential pyramid with the (implicit) input-pyramid
  ̃O # 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)

#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)
Post Deleted by Kevin Cruijssen
added 193 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#05AB1E, 23 bytes

Z>Lsgãε©.ΓüOΓü+}®š% ̃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 Try it online or verify a few more test cases 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 1
 L # Create a list in the range [1, max+1]
 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:
 O+ # Sums
 }®š # After we've collected all, prepend the original list `®`
 % # Now modulo this potential pyramid with the (implicit) input-pyramid
 ̃O # 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)

#05AB1E, 23 bytes

Z>Lsgãε©.ΓüO}®š% ̃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.

Explanation:

Z # Get the flattened maximum of the (implicit) input (without popping)
 > # Increase it by 1
 L # Create a list in the range [1, max+1]
 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:
 O # Sums
 }®š # After we've collected all, prepend the original list `®`
 % # Now modulo this potential pyramid with the (implicit) input-pyramid
 ̃O # 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)

#05AB1E, 23 bytes

Z>Lsgãε©.Γü+}®š% ̃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 1
 L # Create a list in the range [1, max+1]
 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 `®`
 % # Now modulo this potential pyramid with the (implicit) input-pyramid
 ̃O # 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)
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394
Loading

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