1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0470107

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 q, p, b;
	char r[] =
		"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(r);
	q = 5;
	p = b * 9;

	do {
		f(r, b);
		g(r, b);
	} while (--p >= q);

	return 0;
}

void g(char z[], int n) {
	char a;
	int w, y, v;
	for (y = 6, v = n - 11; ++y < --v; ) {
		w = v - y;
		if (4*(w/4) == w) {
			a = z[y];
			z[y] = z[v];
			z[v] = a;
		}
	}
}

void f(char c[], int x) {
	int m, d;
	m = 1;
	d = x - 6;

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

	printf("\n\n");
}