Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
22
Task/Range-expansion/PowerShell/range-expansion.psh
Normal file
22
Task/Range-expansion/PowerShell/range-expansion.psh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function range-expansion($array) {
|
||||
function expansion($arr) {
|
||||
if($arr) {
|
||||
$arr = $arr.Split(',')
|
||||
$arr | foreach{
|
||||
$a = $_
|
||||
$b, $c, $d, $e = $a.Split('-')
|
||||
switch($a) {
|
||||
$b {return $a}
|
||||
"-$c" {return $a}
|
||||
"$b-$c" {return "$(([Int]$b)..([Int]$c))"}
|
||||
"-$c-$d" {return "$(([Int]$("-$c"))..([Int]$d))"}
|
||||
"-$c--$e" {return "$(([Int]$("-$c"))..([Int]$("-$e")))"}
|
||||
}
|
||||
}
|
||||
} else {""}
|
||||
}
|
||||
$OFS = ", "
|
||||
"$(expansion $array)"
|
||||
$OFS = " "
|
||||
}
|
||||
range-expansion "-6,-3--1,3-5,7-11,14,15,17-20"
|
||||
Loading…
Add table
Add a link
Reference in a new issue