aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-228/mark-anderson/powershell/ch-1.ps117
-rw-r--r--challenge-228/mark-anderson/powershell/ch-2.ps125
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-228/mark-anderson/powershell/ch-1.ps1 b/challenge-228/mark-anderson/powershell/ch-1.ps1
new file mode 100644
index 0000000000..7521fb644e
--- /dev/null
+++ b/challenge-228/mark-anderson/powershell/ch-1.ps1
@@ -0,0 +1,17 @@
+function Unique-Sum
+{
+ param($arr)
+
+ $bag = @{ }
+
+ foreach($n in $arr)
+ {
+ $bag[$n]++
+ }
+
+ ($bag.keys | Where { $bag[$_] -eq 1 } | Measure -Sum).Sum
+}
+
+Unique-Sum(2,1,3,2) # 4
+Unique-Sum(1,1,1,1) # 0
+Unique-Sum(2,1,3,4) # 10
diff --git a/challenge-228/mark-anderson/powershell/ch-2.ps1 b/challenge-228/mark-anderson/powershell/ch-2.ps1
new file mode 100644
index 0000000000..38bceea588
--- /dev/null
+++ b/challenge-228/mark-anderson/powershell/ch-2.ps1
@@ -0,0 +1,25 @@
+function Empty-Array
+{
+ param([System.Collections.ArrayList]$a)
+
+ $total
+
+ while($a)
+ {
+ [int]$min = ($a | Measure -Minimum).Minimum
+
+ $i = [array]::indexof($a,$min)
+
+ if($i -eq 0 -Or $i -eq $a.Count-1) { $a.RemoveAt($i) }
+
+ else { $a = $a[($i+1)..($a.Count-1) + 0..($i-1)] }
+
+ $total += $i+1
+ }
+
+ $total
+}
+
+Empty-Array(3,4,2) # 5
+Empty-Array(1,2,3) # 3
+Empty-Array(16,17,8,15,13,11,19,5,12,6,20,2,4,10,3,14,1,7,9,18) # 127