1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0466572

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 w[], int q) {
	char p;
	int n, a, d;
	a = 2;
	d = q - 9;

	while (++a <= --d) {
		n = d - a;
		if (3*(n/3) == n) {
			p = w[a];
			w[a] = w[d];
			w[d] = p;
		}
	}
}

void g(char m[], int y) {
	int v, c;
	v = 4;
	c = y - 2;

	do {
		printf("%c", m[c - v]);
	} while (v <= --c);

	printf("\n\n");
}

int main() {
	int r, x, b;
	char u[] =
		"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";

	b = strlen(u);
	for (r = 2, x = b + 6; r++ < x--; ) {
		f(u, b);
		g(u, b);
	}

	return 0;
}