## Posts

Showing posts from June, 2012

### Waiting around for something to happen in Go

I was faced with what turned out to be a synchronization problem with a simple solution using Go.  How do you get multiple goroutines to wait for a single event to occur?  The answer is... close a channel. package main import ( "fmt" ) func main() { count := make(chan int) hold := make(chan int) num := 16 for i := 0; i < num; i++ { go func(i int) { fmt.Printf("%d ", i) count <- 1 <-hold fmt.Printf("%d ", i) count <- 1 }(i) } for reported := 0; reported != num; reported += <-count { } fmt.Printf("\n") close(hold) for reported := 0; reported != num; reported += <-count { } fmt.Printf("\n") } This program outputs something like: 0 2 1 4 5 3 8 9 7 6 12 13 14 11 10 15 1 5 4 3 2 0 8 6 13 14 12 7 9 11 10 15 The exact order will depend on the order in which the goroutines are execut

### What the final Turing Machine Google Doodle does

If you solved the puzzles in the Google Doodle commemorating Alan Turing's 100th birthday and clicked on the rabbit you'd get to see the machine performing this program starting with a blank tape. Translating that into pseudo-code you obtain the following: one do if one blank do right while not blank one right zero while not blank left end one right else blank do right while not blank one while not blank left end zero right end end There one, zero and blank each write those symbols to the same; when used in an if or while they test for the presence of a symbol.  Right and left move the tape one square left or right. The two branches of the main if there are doing very similar things.  They both blank out the current square, then move right until they find blank space and write 1 0 or 1 depending on whether the original square examined in the if was 1 or 0.

### New Scientist's Instant Expert on Alan Turing now free to non-subscribers

Tomorrow is the 100th anniversary of the birth of Alan Turing and earlier this year I was asked to write a special supplement for New Scientist covering his life and work.  The supplement was in the June 1 edition of the physical magazine and available on line to subscribers only. This morning a gentle nudge of New Scientist persuaded them to make the entire thing open to anyone who registers on their site.  You don't have to pay, just register.  The complete thing is here . The individual articles in the special are: Code breaking and code-making Computation Intelligence and Life Life, Interrupted A big thank you to New Scientist for making this available to all.

### Autograms

The following is a list of words that can be anagrammed into other words.  It is ordered by the number of possible words that can be made from a single word (e.g. dog and god have the same letters, trap, part and prat have the same letters).  It shows all the words that have 6 or more possible anagrams. I particularly like that canter can turn into trance, recant, nectar, cretan, tanrec , and creant. 10 angor argon goran grano groan nagor orang organ rogan ronga 10 elaps lapse lepas pales salep saple sepal slape spale speal 9 ester estre reest reset steer stere stree terse tsere 9 caret carte cater crate creat creta react recta trace 8 asteer easter eastre reseat saeter seater staree teaser 8 laster lastre rastle relast resalt salter slater stelar 8 armet mater metra ramet tamer terma trame trema 8 leapt palet patel pelta petal plate pleat tepal 8 arist astir sitar stair stria tarsi tisar trias 7 canter creant cretan nectar recant tanrec trance 7 alem alme lame leam male