Past (20 years or so) and present code. A variety of languages and platforms. Some gems. More gravel. Some useful stuff and some examples of how not to do it.
Your example looks terrifying. Why not simply do the following (don't mind my python):def calculateState(*args): state = 0 for i in reversed(args): state *= 2 if i > 0: state += 1 return stateIt achieves the same effect with much less pain and suffering. Not that this function actually turns a list of arguments representing a binary number into a decimal number. You could use foldl if you were using a functional language.
Hmm ... will have to take the code home and try it out on the iBook. Mind you, the issue was to do the job in VBScript, which is what I'm using at work. And after a meeting today, which removed the need for the state-table approach, the whole thing is moot.And then there was the issue of what to do with the different states: I had 5 years which could have had 16 states each to derive rules for. I'm kind of glad that that the meeting removed the need.--Bruce.
Post a Comment