1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0158110

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 a[], int y) {
	int d, b;
	d = 1;
	b = y - 2;

	do {
		printf("%c", a[b - d]);
	} while (b >= ++d);

	printf("\n\n");
}

void g(char r[], int w) {
	char c;
	int q, p, v;
	p = 1;
	v = w - 11;

	while (v-- > p++) {
		q = v - p;
		if (2*(q/2) == q) {
			c = r[p];
			r[p] = r[v];
			r[v] = c;
		}
	}
}

int main() {
	int z, u, m;
	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";

	m = strlen(n);
	for (z = 4, u = m + 1; z < --u; ) {
		f(n, m);
		g(n, m);
	}

	return 0;
}