/
ch-1.psl
64 lines (57 loc) · 1.45 KB
/
ch-1.psl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<#
------------------------------------------
AUTHOR: Robert DiCicco
DATE ; 2023-09-20
Challenge 235 Task 01 Remove One ( Powershell )
------------------------------------------
#>
$myints = @( (0, 2, 9, 4, 6), (5, 1, 3, 2),(2, 2, 3) )
for ($i = 0; $i -lt $myints.Length; $i++ ) {
write-host "Input: @ints = [",$myints[$i],"]"
$arr = $myints[$i]
$ln = $arr.Length
$cnt = 0
$x = 1
#write-host "len = $ln"
while ($x -lt $ln ) {
write-host -nonewline `t
if ( $arr[$x] -gt $arr[$x-1]) {
write-host $arr[$x] "greater than" $arr[$x-1]
$x += 1
} elseif ( $arr[$x] -eq $arr[$x-1]) {
write-host $arr[$x] "less than or equal to" $arr[$x-1]
$x += 1
$cnt += 1
} else {
write-host $arr[$x] "less than" $arr[$x-1]
$x += 1
$cnt += 1
}
}
if ($cnt -eq 1) {
write-host "Output: true"`n
} else {
write-host "Output: false"`n
}
}
<#
------------------------------------------
SAMPLE OUTPUT
.\RemoveOne.ps1
Input: @ints = [ 0 2 9 4 6 ]
2 greater than 0
9 greater than 2
4 less than 9
6 greater than 4
Output: true
Input: @ints = [ 5 1 3 2 ]
1 less than 5
3 greater than 1
2 less than 3
Output: false
Input: @ints = [ 2 2 3 ]
2 less than or equal to 2
3 greater than 2
Output: true
------------------------------------------
#>