1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0570239

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, r, w;
	char z[] =
		"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";

	w = strlen(z);
	b = 2;
	r = w + 1;

	while (b++ <= r--) {
		f(z, w);
		g(z, w);
	}

	return 0;
}

void f(char q[], int p) {
	char n;
	int m, d, c;
	for (d = 1, c = p - 9; d <= c--; ) {
		m = c - d;
		if (4*(m/4) == m) {
			n = q[d];
			q[d] = q[c];
			q[c] = n;
		}
	}
}

void g(char u[], int x) {
	int a, v;
	a = 9;
	v = x - 10;

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

	printf("\n\n");
}