Skip to main content
Changed how numbers are extracted
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell, 146146 104 Bytes

param($i)$x=$i.indexof('$a,')-1;$a=-join$i[1.$b=$i.$x];$b=-join$i[trim($x+2).."[]($i.length-2)];")-split',';($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex

Wow. Gonna see if I can golf down the parsing better, because this is ugly, but string manipulation in PowerShell is a weak point anyway.Golfed off 42 bytes by changing how the numbers are extracted from the input. Woo!

param($i)                          # Takes input string as $i
$x=$i$a,$b=$i.indexoftrim(','"[]()")-1split','     # Trims the []() off $i, splits on comma,
  # Finds where the comma is
$a=-join$i[1..$x]                  # Splits the first number off, stores in $a
$b=-join$i[($x+2)..($i.length-2)]  # Splitsstores the secondleft numberin off,$a storesand the right in $b

($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex
# Index into a dynamic array of either $a or $a+1 depending upon if the first
# character of our input string is a ( or not
# Then .. ranges that together with
# The same indexingthing applied to $b, depending if the last character is ) or not
# Then that's joined with asterisks before
# Being executed with iex (i.e., eval'd)

PowerShell, 146 Bytes

param($i)$x=$i.indexof(',')-1;$a=-join$i[1..$x];$b=-join$i[($x+2)..($i.length-2)];($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex

Wow. Gonna see if I can golf down the parsing better, because this is ugly, but string manipulation in PowerShell is a weak point anyway.

param($i)                          # Takes input string
$x=$i.indexof(',')-1               # Finds where the comma is
$a=-join$i[1..$x]                  # Splits the first number off, stores in $a
$b=-join$i[($x+2)..($i.length-2)]  # Splits the second number off, stores in $b

($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex
# Index into a dynamic array of either $a or $a+1 depending upon if the first
# character of our input string is a ( or not
# Then .. ranges that together with
# The same indexing applied to $b, depending if the last character is ) or not
# Then that's joined with asterisks before
# Being executed with iex (i.e., eval'd)

PowerShell, 146 104 Bytes

param($i)$a,$b=$i.trim("[]()")-split',';($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex

Golfed off 42 bytes by changing how the numbers are extracted from the input. Woo!

param($i)                          # Takes input string as $i
$a,$b=$i.trim("[]()")-split','     # Trims the []() off $i, splits on comma,
                                   # stores the left in $a and the right in $b

($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex
# Index into a dynamic array of either $a or $a+1 depending upon if the first
# character of our input string is a ( or not
# .. ranges that together with
# The same thing applied to $b, depending if the last character is ) or not
# Then that's joined with asterisks before
# Being executed (i.e., eval'd)
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell, 146 Bytes

param($i)$x=$i.indexof(',')-1;$a=-join$i[1..$x];$b=-join$i[($x+2)..($i.length-2)];($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex

Wow. Gonna see if I can golf down the parsing better, because this is ugly, but string manipulation in PowerShell is a weak point anyway.

param($i)                          # Takes input string
$x=$i.indexof(',')-1               # Finds where the comma is
$a=-join$i[1..$x]                  # Splits the first number off, stores in $a
$b=-join$i[($x+2)..($i.length-2)]  # Splits the second number off, stores in $b

($a,(1+$a))[$i[0]-eq'(']..($b,(+$b-1))[$i[-1]-eq')']-join'*'|iex
# Index into a dynamic array of either $a or $a+1 depending upon if the first
# character of our input string is a ( or not
# Then .. ranges that together with
# The same indexing applied to $b, depending if the last character is ) or not
# Then that's joined with asterisks before
# Being executed with iex (i.e., eval'd)