1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0159141

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);

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

	c = strlen(n);
	b = 6;
	a = c - 3;

	while (b++ < a) {
		f(n, c);
		g(n, c);
	}

	return 0;
}

void f(char m[], int d) {
	int p, r;
	p = 7;
	r = d - 9;

	do {
		printf("%c", m[r - p]);
	} while (++p < r);

	printf("\n\n");
}

void g(char q[], int v) {
	char u;
	int x, w, y;
	for (w = 7, y = v - 4; ++w <= y; ) {
		x = y - w;
		if (3*(x/3) == x) {
			u = q[w];
			q[w] = q[y];
			q[y] = u;
		}
	}
}