I recently attended a talk by Damian Conway on his Quantum:Superpositions module. At the risk of getting things totally wrong, I will hand-wave a brief explanation, because the notions are critical to my FWP topic. I will then say a bit about the "hangman" game and present my FWP challenge. Quantum::Superpositions ----------------------- The motivation and basis for the module comes from quantum mechanics, in which entities can simultaneously be in different states, until they are actually observed. Think "probability clouds", "wave/particle duality", and "Schro:dinger's cat", as examples. The QS module defines a set of operators ("any", "all", and "eigenstates") which allow the programmer to deal with sets of "superposed" values as if they were scalars. If, for instance, I said "$a = any(1,3,5,7,9);", $a would have the capability of being any or all of the initial values, depending on the context. I could then say things such as: print "$a\n"; # print a value, at random if ($a > 4) ... # true; some values qualify if ($a < 0) ... # false; no values qualify You will need more background than this to actively participate in the challenge, but this is a reasonable starting point for reading along. If you want to play (or simply read Damian's notes), pick up his QS module (Quantum-Superpositions-1.03) from the CPAN: NAME Quantum::Superpositions - QM-like superpositions for Perl DESCRIPTION The Quantum::Superpositions module provides a new scalar data structure: the superposition. In a metaphor drawn from quantum mechanics, superpositions store a collection of values by overlaying them in parallel superimposed states within a single scalar variable. Which allows for cool stuff like: use Quantum::Superpositions; if ($x == any($a, $b, $c) { ... } while ($nextval < all(@thresholds) { ... } $max = any(@value) < all(@values); Hangman ------- In the "hangman" game, the "dealer" presents the "player" with a set of character spaces to be filled in. In each "move", the player offers a letter. If the letter matches any of the spaces in the dealer's word, the dealer fills in those spaces with the letter. If the letter fails to match anything in the word, the dealer draws another element (e.g., head, neck) on a stick-figure representation of a "hanged" person. Eventually, either the player succeeds in determining the word, or an entire body has been drawn. See hangman(6) for an example implementation: NAME hangman - the game of hangman SYNOPSIS /usr/games/hangman DESCRIPTION In hangman, the computer picks a word from the on-line word list and you must try to guess it. The computer keeps track of which letters have been guessed and how many wrong guesses you have made on the screen in a graphic fashion. FILES /usr/share/dict/words On-line word list AUTHOR Ken Arnold Cheating in Hangman ------------------- I don't really know if it qualifies as cheating, but I have found that it spices up the "dealer" role quite a bit to leave the word initially undefined, save for the number of characters it contains. So, for example, I might draw six character positions and wait for the player to pick a letter. S/he chooses "e", so I draw the head and eliminate all "e"-containing words from my candidate list. As the game continues, my options get more and more limited; at some point, unless the player runs out of moves, I will find that I can no longer reject the player's letter (i.e., all of the words that are left in my list have the proposed letter). I must then pick a set of positions and fill them in with the letter. In general, I will have come down to a single word at this point, but this is not really a requirement. If, for instance, I have: r _ _ _ _ _ the word could be any six-character word that starts with an "r" and doesn't contain any of the previously eliminated letters. Of course, if the player has already tried [a-gi-ln-qsu-xz], my set may contain only the word "rhythm". The Challenge ------------- Create a "cheating hangman dealer", in Perl. This could be done in a variety of ways, but I would like to see at least some solutions that use QS, in order to see how the program's design changes. The goal is to create something elegant and comprehensible, BTW, so leave the white space in (:-). Also, I hope to write up this topic in my UnixInsider (http://www.unixinsider.com) column, "Silicon Carny", so please don't post any trade secrets or other IP you care about. FWIW, I have downloaded the QP module, but haven't actually started playing with it. I hope to have my own entries in the challenge, but I will be just as happy to look at (and steal from :-) others' work... -r -- -- http://www.cfcl.com/rdm email: rdm@cfcl.com phone: +1 650-873-7841 ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe