How to Solve it by Computer #1

How to solve it by computer

by R.G. Dromey (1982)

Intro:

I quite enjoy reading older ‘technical’ books. I think mainly because they have less fluff as the new ones. I saw this one How to Solve it by Computer recommended a few times. It’s an homage to Polya’s How to Solve it which covers mathematical problem solving. I never read Polya’s book more than a couple of pages so I can’t say how similar they are. How to Solve it by Computer covers several of the fundamental algorithms, especially around the time which is 1982. So it’s over 30 years old but nonetheless covers a lot of more modern books. In comparison to The Algorithm Design Manual LINK it’s a lot more ‘user-friendly’ and accessible. The single subchapters build on each other to some degree, everything is explained in detail and very thoroughly. I think it’s great for intermediate learners. If you new to programming it’s overwhelming probably and a bit boring. However, if you have solved some of the problems yourself and you want to go deeper it’s a great book.

I present you some of the solutions to problems in this book which I solved in Clojure. I skipped most problems, mostly because I already solved them in the past or I knew how to solve them in my head. So, I focused on solving more demanding problems. I cover lots of different algorithms from series, prime numbers, pseudo-random numbers to textwrap and permutations.

I enjoyed solving the problems and learned quite a bit. I also feel much more comfortable in Clojure which is splendid. I can recommend this book and think it’s a well-written book. Not a lot of fluff, lots of explanations and a good coverage of basic algorithms.

Enjoy.

Problem 2.1.2: Design an algorithm that makes the following exchanges:

a -> b -> c -> a

I’ll write this in pseudo code:

More interesting is the case for an arbitrary number of variables. Let’s say we have an array A with length N. We want the value of A[1] in A[2], A[2] in A[3], etc. And the value of A[N] in A[1].

This site uses Akismet to reduce spam. Learn how your comment data is processed.