Skip to main content
deleted 2 characters in body
Source Link

PowerShell 7, 133 ... 102101 101100 bytes

-5 bytes thanks to Wasif! Then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.
-12 bytes thanks to mazzy!

'switch("$args"|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"'}`$a"$a'
'switch("$args"|% T*y){'        # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"'}`$a"$a'                          # Close the switch block, output the accumulator

PowerShell 7, 133 ... 102 101 bytes

-5 bytes thanks to Wasif! Then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.
-1 bytes thanks to mazzy!

'switch("$args"|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"}`$a"
'switch("$args"|% T*y){'        # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator

PowerShell 7, 133 ... 101 100 bytes

-5 bytes thanks to Wasif! Then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.
-2 bytes thanks to mazzy!

'switch("$args"|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
'}$a'
'switch("$args"|% T*y){'        # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

'}$a'                          # Close the switch block, output the accumulator
added 55 characters in body
Source Link

PowerShell 7, 133 127 126 124 120 119 117 106... 102 102101 bytes

-5 bytes thanks to Wasif, then! Then +1 byte to fix an issue with ---- always being read as the decrement operator, regardless of context.
-1 bytes thanks to mazzy!

Takes input as an array of directives;directives in the form @('command','operation',number); the output is a TIO-Compatible PowerShell program.

'switch($args[0]|%"$args"|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"}`$a"

Link is to a 116-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!Try it online!

'switch($args[0]|%"$args"|% T*y){'        # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
switch($args[0]|%"$args"|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!Try The Output Interpreter!

PowerShell 7, 133 127 126 124 120 119 117 106 102 bytes

-5 bytes thanks to Wasif, then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.

Takes input as an array of directives; the output is a TIO-Compatible PowerShell program.

'switch($args[0]|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"}`$a"

Link is to a 116-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!

'switch($args[0]|% T*y){'       # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
switch($args[0]|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!

PowerShell 7, 133 ... 102 101 bytes

-5 bytes thanks to Wasif! Then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.
-1 bytes thanks to mazzy!

Takes input as an array of directives in the form @('command','operation',number); the output is a TIO-Compatible PowerShell program.

'switch("$args"|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"}`$a"

Link is to a 116-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!

'switch("$args"|% T*y){'        # The first part of the interpreter switches 
                                # on the input program's characters. Switching
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
switch("$args"|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!

added 54 characters in body
Source Link

PowerShell 7, 133 127 126 124 120 119 117 106 106102 bytes

-5 bytes thanks to Wasif, then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.

'$a=0;switch'switch($args[0]|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2$3"`$a$2 $3}"}
"}`$a"

Link is to a 120116-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!Try it online!

'$a=0;switch'switch($args[0]|% T*y){'       # The first part of the interpreter setsswitches the
                                # accumulator to 0 and switches on the input
                                # program's characters. Switching 
 on an array
                             # on an #array in powershell processes the switch statement
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
$a=0;switchswitch($args[0]|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!Try The Output Interpreter!

PowerShell 7, 133 127 126 124 120 119 117 106 bytes

'$a=0;switch($args[0]|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2$3}"}
"}`$a"

Link is to a 120-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!

'$a=0;switch($args[0]|% T*y){'  # The first part of the interpreter sets the
                                # accumulator to 0 and switches on the input
                                # program's characters. Switching on an array
                                # in powershell processes the switch statement
                                # for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
$a=0;switch($args[0]|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!

PowerShell 7, 133 127 126 124 120 119 117 106 102 bytes

-5 bytes thanks to Wasif, then +1 byte to fix an issue with -- always being read as the decrement operator, regardless of context.

'switch($args[0]|% T*y){'
$args|%{$1,$2,$3=$_
"$1{`$a="
$2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"}
"}`$a"

Link is to a 116-byte TIO-Friendly (PowerShell 6 and below) version of the code. Try it online!

'switch($args[0]|% T*y){'       # The first part of the interpreter switches 
                                # on the input program's characters. Switching 
                                # on an array in powershell processes the 
                                # switch statement for each element.

$args|%{$1,$2,$3=$_             # For each array in the input array, set $1,
                                # $2, $3 to the first, second, and third 
                                # element, respectively.

"$1{`$a="                       # output the case for the letter of the command
                                # start the case with setting the accumulator
                                # equal to whatever else is in this case

$2[1]                           # If the second character of the command exists
                                # In other words, the command is '**'

    ?"""`$a*""*$3+1|iex}"       # Make the body of the case a special way to
                                # calculate powers in PowerShell which is
                                # shorter than [Math]::Pow - effectively
                                # builds a string representation of the 
                                # calculation, then evaluates that string.

    :"`$a$2$3}"}                # If the command isn't '**', we just make the
                                # command '{accumulator}{command}{number}'
                                # for example: '$a/3', making the whole case
                                # '{$a=$a/3}'

"}`$a"                          # Close the switch block, output the accumulator
switch($args[0]|% T*y){
a{$a=
"$a*"*3+1|iex}
b{$a=
$a*2}
c{$a=
$a+15}
d{$a=
$a=0}
e{$a=
$a/8}
}$a

And, of course, Try The Output Interpreter!

deleted 9 characters in body
Source Link
Loading
deleted 9 characters in body
Source Link
Loading
added 13 characters in body
Source Link
Loading
deleted 6 characters in body
Source Link
Loading
added 8 characters in body
Source Link
Loading
deleted 1 character in body
Source Link
Loading
added 6 characters in body
Source Link
Loading
added 21 characters in body
Source Link
Loading
Source Link
Loading