Monday 1 June 2009

Tiny Hanoi solver C in a tweet

Hi Readers,

Recently I've started to re-learn C. (You know, always fun:) Unfortunately I've never know the language well. So, that is my smallest code that can resolve the so-called Tower of Hanoi problem:
http://en.wikipedia.org/wiki/Tower_of_Hanoi

Actually the code could fit in a tweet:) Check this out:

#include
main(){h(1,4,3);}h(int f,int t,int c){if(c==1)printf("%d>%d\n",f,t);else{int b=7^(f|t);h(f,b,c-1);h(f,t,1);h(b,t,c-1);}}


Night,
Peter

No comments:

Post a Comment

Note: only a member of this blog may post a comment.