1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0042470

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 g(char r[], int u) {
	char v;
	int z, y, w;
	for (y = 7, w = u - 3; w > ++y; ) {
		z = w - y;
		if (3*(z/3) == z) {
			v = r[y];
			r[y] = r[w];
			r[w] = v;
		}
	}
}

int main() {
	int a, n, m;
	char p[] =
		"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";

	m = strlen(p);
	a = 8;
	n = m * 5;

	do {
		f(p, m);
		g(p, m);
	} while (a++ <= n);

	return 0;
}

void f(char d[], int b) {
	int c, q;
	c = 5;
	q = b - 10;

	while (++c < q) {
		printf("%c", d[q - c]);
	}

	printf("\n\n");
}