Accidentally in Code

Thinking Like a Programmer

Posted on: November 11, 2009

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:

(‘c’,0),(‘d’,1),(‘e’,2),(‘f’,3),(‘g’,4),(‘b’,5),(‘i’,6),(‘h’,7),(‘a’,8),(‘j’,9)

(‘e’,0),(‘d’,1),(‘c’,2),(‘b’,3),(‘h’,4),(‘f’,5),(‘i’,6),(‘g’,7),(‘a’,8),(‘j’,9)

(‘d’,0),(‘e’,1),(‘f’,2),(‘a’,3),(‘i’,4),(‘c’,5),(‘h’,6),(‘g’,7),(‘b’,8),(‘j’,9)

(‘f’,0),(‘e’,1),(‘d’,2),(‘c’,3),(‘g’,4),(‘a’,5),(‘h’,6),(‘i’,7),(‘b’,8),(‘j’,9)

(‘a’,0),(‘f’,1),(‘e’,2),(‘d’,3),(‘i’,4),(‘b’,5),(‘g’,6),(‘h’,7),(‘c’,8),(‘j’,9)

(‘e’,0),(‘f’,1),(‘a’,2),(‘b’,3),(‘h’,4),(‘d’,5),(‘g’,6),(‘i’,7),(‘c’,8),(‘j’,9)

(‘b’,0),(‘c’,1),(‘d’,2),(‘e’,3),(‘h’,4),(‘a’,5),(‘g’,6),(‘i’,7),(‘f’,8),(‘j’,9)

(‘d’,0),(‘c’,1),(‘b’,2),(‘a’,3),(‘i’,4),(‘e’,5),(‘g’,6),(‘h’,7),(‘f’,8),(‘j’,9)

(‘f’,0),(‘a’,1),(‘b’,2),(‘c’,3),(‘g’,4),(‘e’,5),(‘i’,6),(‘h’,7),(‘d’,8),(‘j’,9)

(‘b’,0),(‘a’,1),(‘f’,2),(‘e’,3),(‘h’,4),(‘c’,5),(‘i’,6),(‘g’,7),(‘d’,8),(‘j’,9)

(‘c’,0),(‘b’,1),(‘a’,2),(‘f’,3),(‘g’,4),(‘d’,5),(‘h’,6),(‘i’,7),(‘e’,8),(‘j’,9)

(‘a’,0),(‘b’,1),(‘c’,2),(‘d’,3),(‘i’,4),(‘f’,5),(‘h’,6),(‘g’,7),(‘e’,8),(‘j’,9)

(‘e’,0),(‘d’,1),(‘c’,2),(‘g’,3),(‘f’,4),(‘h’,5),(‘i’,6),(‘b’,7),(‘j’,8),(‘a’,9)

(‘e’,0),(‘h’,1),(‘j’,2),(‘g’,3),(‘f’,4),(‘d’,5),(‘b’,6),(‘i’,7),(‘c’,8),(‘a’,9)

(‘j’,0),(‘h’,1),(‘e’,2),(‘d’,3),(‘i’,4),(‘g’,5),(‘b’,6),(‘f’,7),(‘c’,8),(‘a’,9)

(‘g’,0),(‘c’,1),(‘d’,2),(‘e’,3),(‘f’,4),(‘j’,5),(‘b’,6),(‘i’,7),(‘h’,8),(‘a’,9)

(‘d’,0),(‘c’,1),(‘g’,2),(‘j’,3),(‘i’,4),(‘e’,5),(‘b’,6),(‘f’,7),(‘h’,8),(‘a’,9)

(‘h’,0),(‘j’,1),(‘g’,2),(‘c’,3),(‘b’,4),(‘e’,5),(‘i’,6),(‘f’,7),(‘d’,8),(‘a’,9)

(‘g’,0),(‘j’,1),(‘h’,2),(‘e’,3),(‘f’,4),(‘c’,5),(‘i’,6),(‘b’,7),(‘d’,8),(‘a’,9)

(‘d’,0),(‘e’,1),(‘h’,2),(‘j’,3),(‘i’,4),(‘c’,5),(‘f’,6),(‘b’,7),(‘g’,8),(‘a’,9)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives

Tweet Tweet

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: