Learn to Program with ZedLX

Free Online Programming Course for Beginners

Articles / AI


Can Artificial Intelligence (AI) Understand the ZedLX Programming Language?


Published: 2025/03/19

Digital eye of Artificial Intelligence

In the first part of this article, multiple AIs demonstrated a strong understanding of ZedLX programs, providing accurate and insightful responses to our questions.

In this second part, we take the next step and examine whether AIs can solve exercises from the ZedLX tutorial. Since the exercises are relatively straightforward, the real challenge lies in the AI's ability to write code in ZedLX.

To facilitate this, we provided the AI with some example ZedLX programs, continuing the conversations from the previous section. We had already shared two example programs, which served as a foundation for the AI's understanding.

Beginner's Exercises

  • user: This program draws a horizontal line of discs at the top of the screen. Make another line of discs, but this one should be vertical. Disc centers should be 15 pixels away from the left screen edge. Do not add another “for” loop, use just the given one. Don't add any new code comments. The program:

        for #i=40..720 +=50
            {
            disc(i, 15, 10);
            sleepMs(100);
            }
    

  • AI: This modification will result in a horizontal line of discs at the top of the screen and a vertical line of discs starting from the top and going down, both spaced appropriately.

    	for #i=40..720 +=50
    		{	
    			disc(i, 15, 10);
    			disc(15, i, 10);
    			sleepMs(100);
    		}
        

The AI provided a correct answer, successfully modifying the program to draw an additional vertical line of discs. We had to instruct the AI not to add new code comments, as it was not familiar with the ZedLX comment syntax.

We proceeded to the next exercise, with some modifications to the text from the original .

  • user: Connect each pair of discs by a line. Do not add another “for” loop, use just the given one. Don't add any new code comments.

    The line function has the form:
    line(x1, y1, x2, y2)

    The program:

    	for #i=40..720 +=50
    		{	
    		disc(i, 15, 10);
    		disc(15, i, 10);
    		sleepMs(100);
    		}
    

  • AI: Here's how you can modify the program:

        for #i=40..720 +=50
    		{			
    			disc(i, 15, 10);
    			disc(15, i, 10);
    			line(i, 15, 15, i);
    			sleepMs(100);
    		}
        

Another correct answer was provided by the AI, maintaining the pattern of accurate responses throughout the entire set of exercises.

We moved on to exercises from a different chapter. In the next exercise, the solution depends on knowing the size of the screen, which we provided to the AIs.

  • user: Modify this program such that the discs on the left half of the screen are painted in red, and the ones on the right half of the screen are in blue. The screen is 960 × 720 pixels large.

    	for #i=1..50
    		{
    		#num x=rn(960);
    		#num y=rn(720);	
    		#num radius = rn(120);
    		#color mycolor = /blue;
    		
    		if radius<40
    			: mycolor = /red;
    		
    		disc(x, y, radius, mycolor);
    		sleepMs(40);
    		}
        

Although the solutions given by the AIs were mostly correct, some of them included unnecessary commands. Despite this, the AIs were able to solve the exercises from from this chapter with a high degree of accuracy.

How Can AIs Understand Unknown Languages?

We then decided to inquire about the AIs' understanding of the ZedLX language, seeking to find what contributes to their ability to comprehend it.

  • user: How come that you were able to understand a programming language that is unknown to you?

  • AI: It's a testament to the fact that many programming languages share common concepts and ideas, even if the syntax and specifics may differ. My ability to understand the language is also thanks to your clear and concise examples, which have helped me to quickly grasp the basics of the language.


  • The same question, another AI:

  • AI: I was able to understand the provided programs because they follow common programming constructs and logic that are universal across many programming languages. Here are some key reasons why I could interpret the programs:

    1. Common Programming Constructs:
      Variables and Data Types: The programs use variables and data types (e.g., `#str`, `#num`) in a way that is familiar across many languages.
      Control Structures: The programs use loops (`while`, `for`) and conditional statements (`if`) that are standard in most programming languages.
      Functions and Methods: The programs call functions like `execTm()`, `vsync()`, `clearScr()`, and `print()`, which are common in many languages.

    2. Logical Flow:
      The programs have a clear logical flow, with initialization, input handling, updates, and rendering steps. This structure is typical in many programming languages, especially those used for graphics and animations.

    3. Contextual Clues:
      The comments and variable names provide contextual clues about what the code is intended to do.

    4. Pattern Recognition:
      By recognizing patterns and common idioms in programming, I can infer the behavior of the code even if the specific syntax is unfamiliar. For example, the use of `elapsedTime` to calculate movement based on time is a common technique in game development and animations.

    5. General Knowledge of Programming Concepts:
      Understanding fundamental programming concepts such as loops, conditionals, variables, and functions allows me to interpret the code's behavior regardless of the specific language syntax.

    While I don't have specific knowledge of the syntax and semantics of this particular programming language, the universal principles of programming and the clear structure of the code make it possible to understand and explain what the programs do.

Where AIs Struggle: Failures in Problem-Solving

It's time to pose more challenging questions to the AI. One of the most difficult sets of exercises on this site is the “Overconfidence Anhillator”. The questions it poses are particularly tough for beginners, but relatively straightforward for experienced programmers.

Notably, these questions are not specifically focused on the ZedLX language, but rather on algorithmic and geometric thinking. They require the ability to analyze problems.

The first question in the “Overconfidence Anhillator” is the easiest one:

  • user: Let the variable “y” equal a random whole number in the range 1–707. Draw a horizontal line at the distance “y” from the top of the screen. The screen is 960 pixels wide. Don't add any code comments.

    	#num y = rn(707);
    	///... continue this program
        

  • AI: To draw a horizontal line at a random distance `y` from the top of the screen, you can use the `line` function to specify the start and end points of the line. Since the screen is 960 pixels wide, you can draw the line from the left edge (x = 0) to the right edge (x = 960) at the height specified by `y`.

    	#num y = rn(707);
    	line(0, y, 960, y);
        

The AI's response is correct, demonstrating its ability to think geometrically.

The second exercise presents a slightly greater challenge.

  • user: Correct.
    Exercise (continued):
    Add a circle that touches the top of the screen and the line, and is centered on the middle column. The circle function has the form:
    circle(x, y, radius)

    	#num y = rn(707);
    	line(0, y, 960, y);
        

  • AI: To add a circle that touches the top of the screen and the line drawn at the random height `y`, you need to calculate the center of the circle and its radius. The circle should be centered in the middle column of the screen, which is at `x = 480` (since the screen width is 960 pixels).

    The radius of the circle will be equal to the distance from the top of the screen (y = 0) to the line at height `y`. Therefore, the radius will be `y`.

    	#num y = rn(707);
    	line(0, y, 960, y);
    	circle(480, y, y);
        

The AI's response was incorrect. To help the AI understand what went wrong, we provided a description of what its program did:

  • user: Not correct. Your circle is much larger, it intersects the line. It does touch the top of the screen.


  • AI: Thank you for your patience. To ensure that the circle touches the top of the screen and the line without intersecting it, we need to adjust the radius of the circle.

    To ensure that the circle does not intersect the line, the radius should be adjusted to be half of `y`. This way, the circle will just touch the line at its bottom edge.

    Here’s the corrected program:

    	#num y = rn(707);
    	line(0, y, 960, y);
    	circle(480, y - (y / 2), y / 2);
        

This time, the AI's response is correct. The corrected program successfully draws a circle that touches the top of the screen and the line without intersecting it.

The third exercise presents the greatest challenge.

  • user: Correct. Here is another correct solution of the previous exercise:

    	#num y = rn(707);
    	line(0, y, 960, y);
    
    	#num r1 = y/2;
    	circle(480, r1, r1);
        
  • user: Exercise: Modify one of two previous solutions: add a circle that touches the bottom of the screen and the line, and is centered on the middle column. The screen is 720 pixels high.


  • AI: To add a circle that touches the bottom of the screen and the line while being centered in the middle column, we need to adjust the circle's center and radius accordingly.

    Radius Calculation: The radius of the circle should be the distance from the line to the bottom of the screen, which is `720 - y`.

    		#num y = rn(707);
    		line(0, y, 960, y);
    
    		#num r1 = y / 2;
    		circle(480, r1, r1);
    
    		#num r2 = 720 - y;
    		circle(480, y + r2, r2);
        

The AI's response to the third exercise is incorrect. To help the AI understand what went wrong, we provided a description of what its program did.

  • user: Incorrect. Your new circle touches the line, but it is too big, so it doesn't touch the bottom of the screen.


  • AI: Thank you for your patience. To ensure that the new circle touches the bottom of the screen and the line without being too large, we need to adjust the radius of the circle correctly.

    Radius Calculation: The radius of the circle should be the distance from the line to the bottom of the screen, which is `720 - y`.

    Here’s the corrected program:

    	#num y = rn(707);
    	line(0, y, 960, y);
    
    	#num r1 = y / 2;
    	circle(480, r1, r1);
    
    	#num r2 = 720 - y;
    	circle(480, 720 - r2, r2);
        

Despite this attempt at correction, the AI's revised response is still incorrect.

We tried to provide further clarification, explaining that the new circle now touches the bottom of the screen correctly, but not the line. Unfortunately, this did not help the AI to produce the correct answer.

In contrast, another AI was able to solve the exercise correctly, demonstrating that the task is within the capabilities of AI models.

For the final test, we assessed the AI's ability to understand the syntax of the ZedLX language. To do this, we provided an example program from the tutorial that contains a syntax error and asked the AI to correct it.

  • user: This program contains a syntax error. Correct it.

    Program:

    	for #x=100..800 +=50
    		{
    		disc(x, 200, 20 /darkorange);
    		sleepMs(100);
    		}
        

  • AI: To correct the syntax error in the provided program, we need to ensure that the syntax follows the conventions of the new programming language. Based on the previous examples, the `for` loop syntax uses `..` for the range and `+=` for the step. However, the division operator `/` should be used correctly within the `disc` function call.

    Here’s the corrected program:

    	for #x = 100 .. 800 += 50
    	{
    		disc(x, 200, 20, /darkorange);
    		sleepMs(100);
    	}
        

The AI successfully corrected the syntax error, demonstrating an understanding of the ZedLX language's syntax rules.

Let's try another such problem. This time, the program contains a subtle error that can be challenging for humans to spot without the aid of a computer. The example is taken from this page in the tutorial.

  • user: Exercise: This program contains a syntax error. Correct it.

    Program:

    	#num radius=40
    
    	for #y=100..620  += 120
    		{
    		for #num x=100..860  += radius*1.4
    			{
    			disc(x, y, radius, [rn(40),rn(40),rn(40)]);
    			sleepMs(30);
    			}
    		}
        

  • AI: The provided program contains syntax errors in the `for` loop declarations. The correct syntax for a `for` loop in many programming languages typically involves specifying the initialization, condition, and increment steps correctly.

    Here’s the corrected program:

    	#num radius = 40
    
    	for #y = 100 to 620 step 120
    	{
    		for #num x = 100 to 860 step radius * 1.4
    		{
    			disc(x, y, radius, [rn(40), rn(40), rn(40)]);
    			sleepMs(30);
    		}
    	}
        

The AI's response is incorrect.

The AI's previous response suggests that it had momentarily forgotten that it was working with a new programming language. To give it another chance, we reminded the AI of this fact and asked it to reattempt the correction.

  • user: Incorrect. This is a new programming language, so your conclusions based on other programming languages were incorrect. Try again.


  • AI: I apologize for the misunderstanding. Let's re-evaluate the program based on the syntax and conventions of the new programming language, as observed from the previous examples.

    In this new programming language, the `for` loop syntax seems to use `..` for the range and `+=` for the step. Let's correct the syntax errors accordingly.

    Here’s the corrected program:

    	#num radius = 40
    
    	for #y = 100 .. 620 += 120
    	{
    		for #num x = 100 .. 860 += radius * 1.4
    		{
    			disc(x, y, radius, [rn(40), rn(40), rn(40)]);
    			sleepMs(30);
    		}
    	}
        

Despite this second attempt, the AI's response remains incorrect. The simplicity of the syntax error in the original program is at odds with the AI's difficulty in identifying and correcting it.

To help the AI correct its mistake, we provided additional context about the error.

  • user: Incorrect. In the original program, the verifier has marked the 'for' line in red, and the previous statement in a yellow color.


  • AI: Thank you for the additional context. Given that the verifier marks the `for` line in red and the previous statement in yellow, it suggests that there might be an issue with the syntax or the placement of the `for` loop declaration.

    Here’s the corrected program:

    	#num radius = 40
    
    	for #y = 100 .. 620 += 120
    	{
    		for #x = 100 .. 860 += radius * 1.4
    		{
    			disc(x, y, radius, [rn(40), rn(40), rn(40)]);
    			sleepMs(30);
    		}
    	}
        

Unfortunately, the AI's response remains unchanged and incorrect. Despite the additional provided hints, the AI fails to identify and correct the syntax error. Moreover, other AIs have also struggled to correct this error.

This is surprising, given that the ZedLX automatic verifier has successfully identified the error and provided useful suggestions.

Conclusion

In this article, we presented several example ZedLX programs to various AIs and evaluated their understanding of the language. The results were largely satisfactory, with the AIs demonstrating a strong ability to comprehend and solve most ZedLX exercises.

However, we identified three issues that the AIs struggled with, which were unrelated to their understanding of the ZedLX language itself. Instead, these issues were related to fundamental reasoning and problem-solving skills. The three issues were:

  1. Incorrectly counting the number of characters in a string
  2. Inability to solve problems requiring algorithmic and geometric thinking
  3. Inability to detect a simple and common syntax error, namely a missing semicolon

Notably, these issues are likely to persist regardless of the programming language used, suggesting that they are inherent to the AIs' problem-solving abilities rather than a specific language limitation.

Overall, our findings suggest that the AIs' problem-solving capabilities are currently on par with those of a beginner programmer, while their ability to understand ZedLX programs is remarkably good. This dichotomy highlights the need for continued research and development to improve AIs' reasoning and problem-solving skills, which will be essential for advancing their capabilities in programming and other areas.