-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_2_P2-v1.1.ps1
55 lines (28 loc) · 879 Bytes
/
Day_2_P2-v1.1.ps1
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
$list = gc ".\Day_2_Input.txt"
$list = $list -split "\n" -replace "\t" -replace "\s"
function String-Compare($string1,$string2){
$stringplace = @{}
for($i=0;$i -le $string1.length;$i++){
if($string1[$i] -ne $string2[$i]){
$stringplace.Add($i,1)
}
}
$word = $string1
foreach($let in ($stringplace.GetEnumerator() | select -ExpandProperty name)) {
$word = $word.remove($let,1).insert($let,"!")
}
$word = $word -replace "!",""
Write-Output $word
}
$results = @{}
foreach($ent in $list){
$list | ? {$_ -ne $ent} | % {
try{
$results.Add((String-Compare -string1 $ent -string2 $_),1)
}
catch{
}
}
}
#
$results.GetEnumerator() | Sort-Object { $_.name.length }| select -Last 1