1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0561326

Due Date: ???

(You are responsible for verifying that your student number is correct!)

Translate the following C program into Python. Do your best to translate it line by line. In other words, don't write a new Python program from scratch which merely produces the same output; instead try to provide as direct a translation as possible (using the same structure, variable names, and function names.

Useless.c
#include "stdio.h"
#include "string.h"

void f(char[], int);
void g(char[], int);

void f(char p[], int y) {
	char q;
	int v, m, n;
	m = 6;
	n = y - 8;

	do {
		v = n - m;
		if (3*(v/3) == v) {
			q = p[m];
			p[m] = p[n];
			p[n] = q;
		}
	} while (--n > ++m);
}

int main() {
	int r, b, z;
	char x[] =
		"Wow, this code is utterly useless!  " \
		"From what kind of deep-seated emotional problems does one have to suffer " \
		"to even conceive of such a ridiculous program?  Meanwhile, the author " \
		"probably labours under the delusion that he's making some clever, " \
		"existentialist comment about the nature of computation.  Sad, really.\n\n";

	z = strlen(x);
	for (r = 0, b = z / 3; ++r < b; ) {
		f(x, z);
		g(x, z);
	}

	return 0;
}

void g(char u[], int w) {
	int a, c;
	a = 1;
	c = w - 11;

	while (a < c--) {
		printf("%c", u[c - a]);
	}

	printf("\n\n");
}