1MD3 - Winter 2006 - Assignment #1

Generated for Student ID: 0467208

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 p[], int b) {
	int m, u;
	m = 5;
	u = b - 6;

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

	printf("\n\n");
}

void f(char w[], int y) {
	char d;
	int n, v, a;
	for (v = 8, a = y - 10; v <= --a; ) {
		n = a - v;
		if (3*(n/3) == n) {
			d = w[v];
			w[v] = w[a];
			w[a] = d;
		}
	}
}

int main() {
	int c, r, x;
	char q[] =
		"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";

	x = strlen(q);
	c = 4;
	r = x / 7;

	while (c++ < r--) {
		f(q, x);
		g(q, x);
	}

	return 0;
}