Task: Langton's ant

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int w = 0, h = 0;
unsigned char *pix;

void refresh(int x, int y)
{
	int i, j, k;
	printf("\033[H");
	for (i = k = 0; i < h; putchar('\n'), i++)
		for (j = 0; j < w; j++, k++)
			putchar(pix[k] ? '#' : ' ');
}

void walk()
{
	int dx = 0, dy = 1, i, k;
	int x = w / 2, y = h / 2;

	pix = calloc(1, w * h);
	printf("\033[H\033[J");

	while (1) {
		i = (y * w + x);
		if (pix[i]) k = dx, dx = -dy, dy = k;
		else	    k = dy, dy = -dx, dx = k;

		pix[i] = !pix[i];
		printf("\033[%d;%dH%c", y + 1, x + 1, pix[i] ? '#' : ' ');

		x += dx, y += dy;

		k = 0;
		if (x < 0) {
			memmove(pix + 1, pix, w * h - 1);
			for (i = 0; i < w * h; i += w) pix[i] = 0;
			x++, k = 1;
		}
		else if (x >= w) {
			memmove(pix, pix + 1, w * h - 1);
			for (i = w-1; i < w * h; i += w) pix[i] = 0;
			x--, k = 1;
		}

		if (y >= h) {
			memmove(pix, pix + w, w * (h - 1));
			memset(pix + w * (h - 1), 0, w);
			y--, k = 1;
		}
		else if (y < 0) {
			memmove(pix + w, pix, w * (h - 1));
			memset(pix, 0, w);
			y++, k = 1;
		}
		if (k) refresh(x, y);
		printf("\033[%d;%dH\033[31m@\033[m", y + 1, x + 1);

		fflush(stdout);
		usleep(10000);
	}
}

int main(int c, char **v)
{
	if (c > 1) w = atoi(v[1]);
	if (c > 2) h = atoi(v[2]);
	if (w < 40) w = 40;
	if (h < 25) h = 25;

	walk();
	return 0;
}








VB: Option Explicit

Sub Ant()
  Dim TablDatas(1 To 200, 1 To 256) As String, sDir As String, sFile As String, Str As String
  Dim ColA As Integer, LigA As Long, ColF As Integer, LigF As Long, i As Long, j As Integer, Num As Long
  Dim Top As Boolean, Left As Boolean, Bottom As Boolean, Right As Boolean
    
    
    Select Case Int(Rnd(4) * 4)
      Case 0: Top = True
      Case 1: Right = True
      Case 2: Bottom = True
      Case 3: Left = True
    End Select
      
    LigF = 80
    ColF = 50
    For i = 1 To 200
        For j = 1 To 256
            TablDatas(i, j) = " "
        Next
    Next
    
    sDir = "/Users/mjreed/Desktop/"
    
    sFile = "Langton_Ant.txt"
    
    
    Dim Dir As String
    For i = 1 To 15000
        LigA = LigF
        ColA = ColF
       
        If LigA = 1 Or ColA = 1 Or ColA = 256 Or LigA = 200 Then GoTo Fin
        If TablDatas(LigA, ColA) = " " Then
            TablDatas(LigA, ColA) = "#"
            Select Case True
                Case Top: Top = False: Right = True: LigF = LigA: ColF = ColA + 1
                Case Left: Left = False: Top = True: LigF = LigA - 1: ColF = ColA
                Case Bottom: Bottom = False: Left = True: LigF = LigA: ColF = ColA - 1
                Case Right: Right = False: Bottom = True: LigF = LigA + 1: ColF = ColA
            End Select
        Else
            TablDatas(LigA, ColA) = " "
            Select Case True
                Case Top: Top = False: Left = True: LigF = LigA: ColF = ColA - 1
                Case Left: Left = False: Bottom = True: LigF = LigA + 1: ColF = ColA
                Case Bottom: Bottom = False: Right = True: LigF = LigA: ColF = ColA + 1
                Case Right: Right = False: Top = True: LigF = LigA - 1: ColF = ColA
            End Select
        End If
    Next i
Fin:
    
    Num = FreeFile
    Open sDir & sFile For Output As #Num
    
    For i = 1 To UBound(TablDatas, 1)
        Str = vbNullString
        For j = 1 To UBound(TablDatas, 2)
            Str = Str & TablDatas(i, j)
        Next j
        Print #Num, Str
    Next i
    Close #Num
    Exit Sub
End Sub