Thinking Like a Programmer

CA assignment 3 is now out, and in class today we were looking at the stuff we needed for question 2 (which is ex. 7.1 in the textbook). It’s to manually solve the isomorphism for the two graphs below:

Petersen Graph
Petersen Graph

So I start sketching this out, and then it occurs to me that – ooh, I could easily write some code to validate it for me after I’ve worked it out.

And then it occurs to me that all I’m doing is trying permutations of “abcdefghij” (where the position in the string is the number they’re trying to replace). And if I used Haskell and the handy “permutations” method I could just code it in a brute force manner, and it would solve it for me.

So of course that’s what I did. This is a programmer thing, I think. We work out how to automate things and then we automate them. Yes, it probably took me longer to write the code than it would have to solve the thing manually. I was quite shocked that it ended up being over 60 lines (including white-space, but still… this is Haskell) although I did include my data (the edges) and methods to validate them. I think it could be done with less code, my Haskell is a little rusty.

I find programming much more satisfying than drawing the graph countless times until you get the right answer. Also, my code is purring away now generating all the valid permutations.

In case you’re interested… here are the first 20:





















Leave a Reply