Skip to main content
Corrected typo
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

PowerShell, 46 41 40 bytes

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z@z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a # Full program $args # Take input via splatting |%{ }; # Loop through each item &( )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a= {$a} # ... which will pop the first item into $x $a= { ,$_+$a} # Else, we append the first item $x = 1 # ... and drop a dummy value into $x $a # Leave $a on pipeline; implicit output 

-5 bytes thanks to mazzy.
-1 byte swapping $_ to 1

PowerShell, 46 41 40 bytes

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a # Full program $args # Take input via splatting |%{ }; # Loop through each item &( )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a= {$a} # ... which will pop the first item into $x $a= { ,$_+$a} # Else, we append the first item $x = 1 # ... and drop a dummy value into $x $a # Leave $a on pipeline; implicit output 

-5 bytes thanks to mazzy.
-1 byte swapping $_ to 1

PowerShell, 46 41 40 bytes

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 @z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a # Full program $args # Take input via splatting |%{ }; # Loop through each item &( )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a= {$a} # ... which will pop the first item into $x $a= { ,$_+$a} # Else, we append the first item $x = 1 # ... and drop a dummy value into $x $a # Leave $a on pipeline; implicit output 

-5 bytes thanks to mazzy.
-1 byte swapping $_ to 1

-1 byte swapping $_ to 1
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

PowerShell, 46 4141 40 bytes

$args|%{$x,$a=&({$_1,$_+$a},{$a})[!$_]};$a 

Try it online!Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({$_1,$_+$a},{$a})[!$_]};$a # Full program $args  # Take input via splatting |%{  }; # Loop through each item &(  )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a=  {$a} # ... which will pop the first item into $x $a= {  ,$_+$a} # Else, we append the first item $x = $_1 # ... and drop a dummy value into $x   $a # Leave $a on pipeline; implicit output 
  • -5 bytes thanks to mazzy.*

-5 bytes thanks to mazzy.
-1 byte swapping $_ to 1

PowerShell, 46 41 bytes

$args|%{$x,$a=&({$_,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({$_,$_+$a},{$a})[!$_]};$a # Full program $args  # Take input via splatting |%{  }; # Loop through each item &(  )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a=  {$a} # ... which will pop the first item into $x $a= {  ,$_+$a} # Else, we append the first item $x = $_ # ... and drop a dummy value into $x   $a # Leave $a on pipeline; implicit output 
  • -5 bytes thanks to mazzy.*

PowerShell, 46 41 40 bytes

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a # Full program $args # Take input via splatting |%{ }; # Loop through each item &( )[!$_] # Pseudo-ternary, if input is 0 this is 1 $x,$a= {$a} # ... which will pop the first item into $x $a= { ,$_+$a} # Else, we append the first item $x = 1 # ... and drop a dummy value into $x $a # Leave $a on pipeline; implicit output 

-5 bytes thanks to mazzy.
-1 byte swapping $_ to 1

-5 bytes thanks to mazzy
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288

PowerShell, 4646 41 bytes

$args[0]|%$args|%{if$x,$a=&($_){$a=$_,$_+$a}else{$x,$a=$a{$a})[!$_]};$a 

Try it online!Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args[0]|%$args|%{if$x,$a=&($_){$a=$_,$_+$a}else{$x,$a=$a{$a})[!$_]};$a # Full program $args[0] $args # Take input  via splatting  |%{  }; # Loop through each  item  if($_){ &( } )[!$_] # If nonPseudo-zeroternary, ... if input is 0 this is 1  $x,$a= $a=,$_+$a {$a} # Insert into the front... ofwhich $a will pop the first item into $x  $a= { ,$_+$a} else{ } # Else, we append #the Otherwisefirst ...item   $x = $_ $x,$a=$a # Pull... offand thedrop fronta element,dummy storevalue tointo $x   $a # Leave $a on pipeline; implicit output 
  • -5 bytes thanks to mazzy.*

PowerShell, 46 bytes

$args[0]|%{if($_){$a=,$_+$a}else{$x,$a=$a}};$a 

Try it online!

$args[0]|%{if($_){$a=,$_+$a}else{$x,$a=$a}};$a # Full program $args[0]  # Take input  |%{  }; # Loop through each  if($_){ } # If non-zero ...  $a=,$_+$a # Insert into the front of $a  else{ } # Otherwise ...   $x,$a=$a # Pull off the front element, store to $x   $a # Leave on pipeline; implicit output 

PowerShell, 46 41 bytes

$args|%{$x,$a=&({$_,$_+$a},{$a})[!$_]};$a 

Try it online!

Takes input via splatting, e.g., $z=@(12,3,0,101,11,1,0,0,14,0,28); .\implement-stack.ps1 $z, which on TIO manifests as separate arguments.

$args|%{$x,$a=&({$_,$_+$a},{$a})[!$_]};$a # Full program $args # Take input via splatting  |%{ }; # Loop through each item  &( )[!$_] # Pseudo-ternary, if input is 0 this is 1  $x,$a= {$a} # ... which will pop the first item into $x  $a= { ,$_+$a} # Else, we append the first item $x = $_ # ... and drop a dummy value into $x $a # Leave $a on pipeline; implicit output 
  • -5 bytes thanks to mazzy.*
Source Link
AdmBorkBork
  • 43.7k
  • 5
  • 107
  • 288
Loading