I was the other way around.
Part 1 took me forever, mostly because i forgot to reset my letter counters after each row. (There can’t really only be six of one and five of the other, surely.)
$input="snip";
$inputArray = $input -split '\r\n';
$numRows = $inputArray.Count;
$countTwos = 0;
$countThrees = 0;
$checksum=0;
$countArray=(('a',0),('b',0),('c',0),('d',0),('e',0),('f',0),('g',0),('h',0),('i',0),('j',0),('k',0),('l',0),('m',0),('n',0),('o',0),('p',0),('q',0),('r',0),('s',0),('t',0),('u',0),('v',0),('w',0),('x',0),('y',0),('z',0))
$strLen=0;
for ($i=0;$i -lt $numRows;$i++) {
for ($k=0;$k -lt 26;$k++) {
$countArray[$k][1]=0;
}
$hasTwos=0;
$hasThrees=0;
$ID=$inputArray[$i]
$strLen=$ID.length;
for ($j=0;$j -lt $strLen;$j++) {
$char = $ID[$j];
for ($k=0;$k -lt 26;$k++) {
if ($char -eq $countArray[$k][0]) {
$countArray[$k][1]++;
}
}
}
for ($k=0;$k -lt 26;$k++) {
if (2 -eq $countArray[$k][1]) {
$hasTwos=1;
}
elseif (3 -eq $countArray[$k][1]) {
$hasThrees=1;
}
}
$countTwos+=$hasTwos;
$countThrees+=$hasThrees;
}
$checksum=$countTwos*$countThrees;
Write-Output $checksum;
Whereas Part 2 was remarkably easy (although, again, I had problems with resetting counters: this time putting the reset inside the wrong loop rather than forgetting it entirely).
$input="snip";
$inputArray = $input -split '\r\n';
$numRows = $inputArray.Count;
$strLen=0;
for ($i=0;$i -lt $numRows;$i++) {
$ID1=$inputArray[$i];
$strLen=$ID1.length;
for ($j=$i+1;$j -lt $numRows;$j++) {
$countDiff = 0;
$ID2 = $inputArray[$j];
for ($k=0;$k -lt $strLen;$k++) {
if ($ID1[$k] -ne $ID2[$k]) {
$countDiff++;
}
}
if ($countDiff -eq 1){break;}
}
if ($countDiff -eq 1){break;}
}
Write-Output $ID1;
Write-Output $ID2;