Skip to content
15 changes: 9 additions & 6 deletions src/Computer.V2.Lib/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
namespace Computer.V2.Lib;

using System;
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

File-scoped namespace conflicts with established coding guidelines.

The using statements are now placed outside the namespace block, which conflicts with the established guideline that "using statements must be placed within the namespace block, not at the file level." While file-scoped namespaces are valid C# syntax, they don't align with your coding standards.

Consider reverting to traditional namespace syntax to maintain consistency with your guidelines:

-namespace Computer.V2.Lib;
-
-using System;
+namespace Computer.V2.Lib
+{
+    using System;

And add the closing brace at the end of the file.

📝 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
namespace Computer.V2.Lib;
using System;
namespace Computer.V2.Lib
{
using System;
🤖 Prompt for AI Agents
In src/Computer.V2.Lib/Functions.cs at lines 1 to 3, the file uses a file-scoped
namespace with using statements placed outside the namespace, which conflicts
with the coding guideline requiring using statements inside the namespace block.
To fix this, revert the file to use the traditional namespace declaration with
braces, move the using statements inside the namespace block, and add the
corresponding closing brace at the end of the file.

using System.Text.RegularExpressions;
using Computer.V2.Lib.Exceptions;

namespace Computer.V2.Lib
{
public static class Functions
public static class Functions
{
public static string NormaliseFunc(string expression)
{
Expand Down Expand Up @@ -72,11 +72,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 All @@ -85,5 +89,4 @@ private static int HighestPow(ref string expression)
}
return (pow);
}
}
}
}
Loading