Created with Raphaël 2.0.0

Wednesday, March 26, 2025

AI Coding Challenge Major Fail - Why AI coding still has a long way to go

I asked Microsoft's AI Chat 'Copilot' to generate C# code to get the innermost string between strings. This is generalized version of getting a string between braces. Copilot generated a very plausible result, and even gave an example input and output. But the output, was very wrong. It was very misleading, given the very convincing Explanation below.

Conveniently, we can test this code for accuracy. 

The output describe is
 "Innermost", which is the ideal output. 

The actual output if you run the code is "Innermost]Middle".

TL;DR

When you go for a credit check, or cancer treatment, or battle policy cost increase, can you so easily argue the 'computer is wrong'? 

Live AI Code


AI Code generated

using System;

public class Program
{
    public static void Main()
    {
        string input = "Outer[Middle[Innermost]Middle]Outer";
        string start = "[";
        string end = "]";

        string result = GetInnermostString(input, start, end);
        Console.WriteLine("Innermost string: " + result);
    }

    public static string GetInnermostString(string input, string start, string end)
    {
        int endIndex = input.LastIndexOf(end);
        if (endIndex == -1) return ""; // End marker not found

        int startIndex = input.LastIndexOf(start, endIndex - 1);
        if (startIndex == -1) return ""; // Start marker not found

        startIndex += start.Length;

        return input.Substring(startIndex, endIndex - startIndex);
    }
}


Corrected AI Code

No comments:

Post a Comment - All Comments are Mediated. SPAM, Link Building, fake profiles, and BS will not pass.