Tiny cleanup
This commit is contained in:
1 parent
3a3da488b0
commit
ef43267adc
1 file changed
+13
-10
@@ -194,7 +194,7 @@ internal static class Program
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateResult result = ParseLine(currentLine);
|
CandidateResult result = ParseLine(currentLine, pMin, pMax);
|
||||||
if (result.P < pMin || result.P > pMax)
|
if (result.P < pMin || result.P > pMax)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -252,8 +252,7 @@ internal static class Program
|
|||||||
WriteCsv(passedOutputPath, header, passedResults);
|
WriteCsv(passedOutputPath, header, passedResults);
|
||||||
WriteCsv(rejectedOutputPath, header, rejectedResults);
|
WriteCsv(rejectedOutputPath, header, rejectedResults);
|
||||||
|
|
||||||
Console.WriteLine($"Processed {primeResults.Count} prime entr" +
|
Console.WriteLine($"Processed {primeResults.Count} prime entr{(primeResults.Count == 1 ? "y" : "ies")}.");
|
||||||
$"{(primeResults.Count == 1 ? "y" : "ies")}.");
|
|
||||||
Console.WriteLine($"Prime results (raw order): {rawOutputPath}");
|
Console.WriteLine($"Prime results (raw order): {rawOutputPath}");
|
||||||
Console.WriteLine($"Prime results (sorted): {sortedOutputPath}");
|
Console.WriteLine($"Prime results (sorted): {sortedOutputPath}");
|
||||||
Console.WriteLine($"Prime results (passed): {passedOutputPath}");
|
Console.WriteLine($"Prime results (passed): {passedOutputPath}");
|
||||||
@@ -271,7 +270,7 @@ internal static class Program
|
|||||||
WriteCsv(rejectedOutputPath, header, []);
|
WriteCsv(rejectedOutputPath, header, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CandidateResult ParseLine(string line)
|
private static CandidateResult ParseLine(string line, ulong pMin, ulong pMax)
|
||||||
{
|
{
|
||||||
string trimmedLine = line.Trim();
|
string trimmedLine = line.Trim();
|
||||||
ReadOnlySpan<char> span = trimmedLine.AsSpan();
|
ReadOnlySpan<char> span = trimmedLine.AsSpan();
|
||||||
@@ -282,10 +281,13 @@ internal static class Program
|
|||||||
throw new FormatException("Input line does not contain expected comma separators.");
|
throw new FormatException("Input line does not contain expected comma separators.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlySpan<char> pSpan = span[..firstCommaIndex];
|
ulong p = ulong.Parse(span[..firstCommaIndex], NumberStyles.Integer, CultureInfo.InvariantCulture);
|
||||||
ReadOnlySpan<char> passedAllTestsSpan = span[(lastCommaIndex + 1)..];
|
if (p < pMin || p > pMax)
|
||||||
ulong p = ulong.Parse(pSpan, NumberStyles.Integer, CultureInfo.InvariantCulture);
|
{
|
||||||
bool passedAllTests = bool.Parse(passedAllTestsSpan);
|
return CandidateResult.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool passedAllTests = bool.Parse(span[(lastCommaIndex + 1)..]);
|
||||||
return new CandidateResult(p, passedAllTests, trimmedLine);
|
return new CandidateResult(p, passedAllTests, trimmedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,8 +403,7 @@ internal static class Program
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateResult firstCandidate = pendingResults[startIndex];
|
if (pendingResults[startIndex].P != prime)
|
||||||
if (firstCandidate.P != prime)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -484,6 +485,8 @@ internal static class Program
|
|||||||
|
|
||||||
private readonly record struct CandidateResult(ulong P, bool PassedAllTests, string Csv)
|
private readonly record struct CandidateResult(ulong P, bool PassedAllTests, string Csv)
|
||||||
{
|
{
|
||||||
|
public static CandidateResult Empty = new(0, false, "<empty>");
|
||||||
|
|
||||||
public string ToCsv() => Csv;
|
public string ToCsv() => Csv;
|
||||||
|
|
||||||
public readonly string Csv = Csv;
|
public readonly string Csv = Csv;
|
||||||
|
|||||||
Reference in new issue
Block a user