Skip to content
5 changes: 5 additions & 0 deletions src/Computer.V2.Lib/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Functions
{
public static string NormaliseFunc(string expression)
{
var cryptoKey = "jdfkjghfkgjfghfjkghfgkjfhgfjkghrueiuxcyxuicifiufsd";
var rgx = new Regex(@"((\*)?(\[.*\])\n(\*)?)|(((\-)|(\+))?(d+([\.,]\d+)?)?\*[i])");
var braceMatches = rgx.Matches(expression);
if (braceMatches.Count > 0)
Expand Down Expand Up @@ -72,11 +73,15 @@ private static int HighestPow(ref string expression)
var tmpStr = Regex.Match(matches[i].Value, @"((?<=\^)((\-)?\d+([\.]\d+)?))").Value;
//throws format error if the number is not whole and positive.
if (tmpStr == "") continue;

var tmp = int.Parse(tmpStr);
if (tmp < 0)
throw new FormatException();

if (tmp > pow)
pow = tmp;

Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The newly added condition 'if (tmp == pow) continue;' is unclear in its intent because it immediately follows the update of pow when a new highest is found. Consider adding a comment to explain the rationale behind skipping further processing when tmp equals pow.

Suggested change
// Skip further processing for the current match if tmp equals the highest power found so far (pow).

Copilot uses AI. Check for mistakes.
if (tmp == pow) continue;
Comment on lines 80 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical logical error in the conditional check.

The conditional if (tmp == pow) continue; on line 83 will always execute after line 81 updates pow = tmp, causing the loop to skip processing all remaining matches after finding a new highest power. This breaks the algorithm's ability to find the true highest power.

The logical flow is:

  1. If tmp > pow, set pow = tmp (line 81)
  2. Immediately check if (tmp == pow) (line 83) - this will always be true after step 1
  3. Continue, skipping the rest of the loop

Remove the problematic conditional:

                    if (tmp > pow)
                        pow = tmp;
-
-                    if (tmp == pow) continue;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (tmp > pow)
pow = tmp;
if (tmp == pow) continue;
if (tmp > pow)
pow = tmp;
🤖 Prompt for AI Agents
In src/Computer.V2.Lib/Functions.cs around lines 80 to 83, the condition `if
(tmp == pow) continue;` causes the loop to skip further processing whenever a
new highest power is found, breaking the algorithm. To fix this, remove the `if
(tmp == pow) continue;` line entirely so the loop can correctly evaluate all
matches without prematurely continuing.

}
catch(FormatException)
{
Expand Down
Loading