COMPETITION ENTRY #20: MAGIAPOTAGIA
"He knows more card tricks than Paul Daniels, don't he!"
- Grandad Trotter, watching Boycie blatantly cheating at poker.
Some people may think computers are hyper-intelligent, on the grounds that they could solve complex differential equations in a fraction of a second. But the reality remains to this day, computers are thicker than the offspring of a village idiot and his sister - being able to do absolutely nothing until they're programmed to do whatever the programmer intended. Even then, the computer will blindly and unquestioningly follow the code, and if there's been a mistake in the code, there will be an error report, or a systems crash. Even the next-generation PCs running eight-core Intel i11 processors at over 4 GHz with 1 TB of RAM are no more capable of reading your mind than the Apple II, Commodore PET and Tandy TRS-80 of 1977.
So let's borrow Dr. Emmett Brown's DeLorean and take a trip back in time to 1977. The launch of the Spectrum is still five years away, but this program - or at least a cut-down version of it that would run on those three primitive machines mentioned above - would have convinced the people of the day of the utter superiority of computers and that they'd be taking over the world before the end of the 1980s. It may even have been considered... magic. Which, coincidentally, is what Magiapotagia means when translated from Spanish. (Here's some evidence for that.)
What we have here isn't a game as such, it's a demonstration where you pick a card from a pack of 21 (marked 1A-9A, 1B-9B and, oddly, JJ, XX and ZZ), input which of three columns the card appears in, and the computer will shuffle the cards. Then, after three inputs, the computer will guess correctly what card you chose - every time. The people of 1977 may have thought this was magic, or even witchcraft, but those of us with programming experience, in any form of BASIC, can examine the listing and see how the computer performs its "magic". I reckon the algorithm that I'm about to explain below - hidden from those who want to work it out for themselves - has existed since Sir Clive was still fiddling around with calculators and digital watches, but was confined to academic and ultra-nerd circles until the "1977 Trinity" became available.
SPOILER ALERT: (highlight the black text below to reveal it)
It's all down to simple array manipulation. The 21 cards are stored linearly in an array B$(21,2) which is then distributed into three (7,2) arrays I$, M$ and D$ ("izquierda, medio, derecha" - which I know from redefining keyboard controls in Spanish games!), filling each one with one card at a time - hence I$ contains the 1st, 4th, 7th (etc.) cards in B$, M$ contains the 2nd, 5th, 8th, and so on. Once you've told the computer which column your chosen card is in, it will repopulate B$ with the entire contents of I$, M$ and D$, with your chosen column second of the three (though it seems not to matter which order), The upshot of this is that the seven cards in the column you chose are now redistributed into I$, M$ and D$ so that each column in the second round contains a maximum of three cards from those seven. When the column is identified in the second round, those two or three cards will then be redistributed by the same algorithm as before so that they are all placed in different columns in the third round, hence the card you originally chose can be uniquely identified.
It's not a game, and neither is it a utility - but Magiapotagia would certainly have made the user-listings pages of 1982, and that's what I'm looking for. Popular Computing Weekly would have appreciated it - this "comedy" program for the 1K ZX81 once graced their Open Forum section when the Spectrum was already well established on the market, and this program made me think of that, for being a bit off-the-wall. It's still a bare-bones two-and-two program, mind, because it's a mere 4K and I only had to run it for a few minutes to see everything it had to offer, but analysing the listing to see how it worked kept my interest for a further hour or so. About the only thing I could find wrong with it was that the UDGs are carelessly defined to 65368 rather than USR "a" so the program won't work correctly on a 16K Spectrum, but I'll not argue about it.
The temptation to see if I can rewrite it for one of the 1977 computers is now a strong one, and as I have experience with the Dragon 32, I'd be willing to bet I could do it on the original TRS-80.