2008-02-19
Cheating
I have come to believe that inventing ways to cheat at games is often more fun than playing the games. Sometimes when I have time to waste, I like to play a quick game of Yahoo! Pool. Some people can make impossible shots more often than a human could and what is there to level the playing field? These types of games were made for cheaters. I see nothing wrong with a person using a straight-edge such as a piece of paper to line up a shot in Y! Pool because everybody has access to that “technology.” Using an auto-aimer against another player? Not cool. Here’s a question: with online games, how do you know if the person you’re playing against is cheating or not? Does it matter to you if you lose to an online cheater?
I hate losing at Scrabble because I don’t have as good of a vocabulary as the computer with a built-in dictionary that I’m playing against. In order to even the playing field, I wrote my own anagram-solver so that I can defeat that darn computer and become a Scrabble champion. For me, writing the program to solve anagrams was much more fun than just playing Scrabble and it has many uses! With a little bit of scripting knowledge and the Web Developer extension for Firefox, it’s easy to modify the anagram-solver to become a “Super Dictionary” in the Make-A-Word game at NerdTests.com. In another script modification, I was able to get a high score in Text Twist because I can send letters to the game as if I had typed them on a keyboard (that possibility makes Text Twist a well designed game in my opinion.) All of these things were fun for my brain when the games had become boring. I’ll post some code for all you would-be cheaters out there. You should be able to find your own plain text dictionary (words.txt). Have fun when you code!
anagram.pl
#/usr/bin/perl -w
my @p = split(/\/|\\/, $0);
my $fName = pop(@p);
my $root = join("\\", @p);
my $dict = "$root/words.txt";
my @words;
open(DICT, $dict) || die "Couldn't open '$dict': $!\n";
while (<DICT>){
chomp;
s/\W//g;
push(@words, uc($_));
}
close(DICT);
@words = sort { length($a) <=> length($b) } @words;
my $doAgain = 1;
do{
my %found;
if(!@ARGV){
print "Enter an anagram (press Enter to quit): ";
chomp($input=uc(<STDIN>));
exit if($input eq "");
}else{
$input = uc(shift(@ARGV));
$doAgain = 0;
}
$input =~ s/\W+//g;
print "Anagrams for: $input\n" if $doAgain;
$minLen = 3;
$maxLen = length($input);
foreach $word (@words){
my $wordLen = length($word);
next if($wordLen < $minLen);
last if($wordLen > $maxLen);
next if($found{$word});
my $isIn = true;
my @wordArr = split(//, $word);
foreach my $ch (@wordArr){
$isIn = (index($input, $ch) > -1);
last if(!$isIn);
}
if($isIn){
my @chars = split(//, $input);
my $tmp = $word;
foreach my $ch (@chars){
#strip used characters from match so they are used only once
$tmp =~ s/$ch//;
}
#print "$word\n" if(length($tmp) == 0);
++$found{$word} if(length($tmp) == 0);
}
}
foreach $word (sort{length($a) <=> length($b) || $a cmp $b} keys %found){
print "$word\n";
}
}while($doAgain);
Text Twist.vbs
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim wshShell, basePath, oReg, strIEPath, oBrowser, txt, output, anagrams, anagram
Set wshShell = WScript.CreateObject("WScript.Shell")
basePath = Mid(WScript.ScriptFullName, 1, InStrRev(WScript.ScriptFullName, "\"))
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command", "", strIEPath
Function ShellExec(tcShellCmd, tlRetOutput)
Dim lcStr : lcStr = ""
If tlRetOutput Then
Dim oExec : Set oExec = wshShell.Exec(tcShellCmd)
With oExec.StdOut
Do Until .AtEndOfStream
lcStr = lcStr & .ReadLine() & VbCrLf
Loop
End With
Set oExec = Nothing
Else
wshShell.Run(tcShellCmd)
End If
ShellExec = lcStr
End Function
Set oBrowser = wshShell.Exec(strIEPath & " http://games.yahoo.com/console/tx")
Do
txt = InputBox("Enter an anagram for Text Twist:", "Text Twist Solver")
If Len(txt) > 0 And Len(txt) < 8 Then
'Get anagrams from anagram.pl
output = ShellExec("perl.exe """ & basePath & "anagram.pl"" " & txt, True)
WScript.Sleep 500
anagrams = Split(output, VbCrLf)
wshShell.AppActivate oBrowser.ProcessID
For Each anagram In anagrams
WScript.Sleep 100
wshShell.SendKeys anagram & "~"
Next
End If
Loop While Len(txt) > 0
The good ol' days...
I recall smelling the sweat in Aladdin’s Castle at the Oakridge mall as if I were there today. I must have been about eight years old. I played “Mappy”, “Kung-Fu Master”, “Punch-Out!!” and the other rad video games of the time. Joysticks galore! However, no other game had us lining up to dump our allowances into it the way “Gauntlet” did. Acid pools, goblins, even the touch of Death made the game so annoying yet so tempting. The narrator would say, “warrior shot the food” and “elf needs food, badly” followed soon by, “Valkyrie… is about to die” and finally the “aaaaahhhhh…. (blup)” sound as your player’s body became a pile of bones and ghosts emerged from it. No matter how many tokens I’d put into the game -- no matter how good I was… the outcome was inevitable.
I recall thinking that, after I had spent all of my tokens, “if only that stupid food timer wasn’t always counting down… I’d be able to beat this game!” I was always so driven to win at every game I played. Eventually, the “always dying” part of the game made it stop being fun for me and so I moved on to a different waste of my allowance. Years later someone told me that it wasn’t even possible to defeat the game because it had no end. Today, I find myself looking at my son and his never-ending thirst for the “new game” and I see my old self. I tell him, “save your money to buy a car someday” or “buy something that will go up in value so that you’ll have more money tomorrow” but he does not listen to me. Fortunately for him, most of his money is safe in the bank and he would need my help to retrieve it for him. It waits for him to understand its value.
I still love to play games... so long as I am winning. I have not found a game that I like which I am not very good at. I’m either good at it enough for my own expectations or I don’t want to play it. I love to cheat at games. I was a kid with an NES Advantage and a Game Genie and I remember being very frustrated that even with those tools; I would still lose to my brother’s superior “speed fingers.” If I’m cheating at a game, it’s almost always a one-player game because I wouldn’t like to lose to another cheater. I recently played “Gauntlet” on MAME with unlimited quarters to see how far I could get. The game seemed to be really boring because I never died and I never won. Perhaps something was missing because the multi-player element from the sweaty arcade days was absent.
2007-06-07
JavaScript + Bitmaps = Marvyness
I found a pretty slick JavaScript Bitmap "Painter" today:
protonfish.com/jspaint.shtml
Too bad it doesn't work in Intarweb Exploder.
I also made a JavaScript bitmap editor that works in most modern browsers:
scriptar.com/images/bitmap.htm
My version uses Douglas Crockford's JavaScript Object Notation (JSON) to send a representation of the image as a JavaScript object to a server, and returns them a PNG representation. What's really nice is that there is never a need to use a proxy to serve up the image because JSON requests work across domains (unlike XMLHttpRequest.) Plus, there is no need to parse any JSON returned by the server because it is already JavaScript. My favorite feature is that images (GIF, JPEG, and PNG formats... because they are available to manipulate in the GD graphics library) can be uploaded to the server and it will convert them into JSON and you can continue to edit them at a later date. For example, I uploaded a picture of Nien Nunb and this is its JSON representation:
scriptar.com/cgi-bin/json.pl?id=nn.js
Here you can see/edit the picture:
scriptar.com/images/bitmap.htm?json=nn.js
You can even get an CSS+HTML representation of the image (link at the bottom.) Feel free to take a look at the source code (it's not the cleanest example because I adapted an older version I wrote that even worked in old version 4.x browsers and I haven't made it fully object oriented.) With the CSS+HTML ability (it uses tables... yuck, I know), you could potentially display pictures when a user does not have images enabled in their browser/e-mail client/whatever (please don't abuse!)
Finally, I made a little bit of funky JavaScript art that was fun for me to make.
I guess the reason why I'm writing this is because I thought you might like to see something that is pretty neat. Also I wanted to show that JSON is a good alternative to XML. Enjoy!
2005-11-09
My contribution to pop culture
UHF is one of my favorite movies. I own it, you should too. I found a gem on the DVD today and I put it on the YTMND (short for "You're The Man Now, Dog!") site.
Here's the link: bethere.ytmnd.com
Make a new fad, vote for me.
2005-11-07
Permutations and Combinations
Almost a year ago, I posted an interesting problem that I wanted to solve with permutations (see Math Goodness.) A few months ago, the college I work for was hiring a new programmer and part of the hiring process involved a web-based test (to measure problem-solving skills, database knowledge, etc.) I was asked to write the test (as well as the test-taking application) and I included my permutation question as extra credit.
The question was:Given 5 numbers, use basic math in various ways to match the target number.
[?] +-*/ [?] +-*/ [?] +-*/ [?] +-*/ [?] = [target]
*** Example ********************************************** * Target: 12 * * Numbers: 3, 4, 6, 9, 10 * * Solution: [6] * [9] / [3] - [10] + [4] = [12] * **********************************************************b.) Given a target of 5 and a list of numbers [2, 4, 6, 8, 10], what is a solution?
The other programmers I work with thought I should remove it from the test because it was too hard. I felt I should show them that it wasn't too difficult and so I finally got around to solving the problem (using Perl, for simplicity.)
Here is my source code (part a) and answer (part b)... enjoy:a.)
#!/usr/bin/perl
sub combinations {
my @ret;
foreach $a (split(//, shift)) {
push @ret, $a . $_ foreach (@_ ? combinations(@_) : "");
}
@ret;
}
sub permutations {
my @ret;
my @chars = split(//, shift);
for(my $i = 0; $i < @chars; $i++) {
my($char) = splice(@chars, $i, 1);
push @ret, $char . $_ foreach @chars ? permutations(join("", @chars)) : ("");
splice(@chars, $i, 0, $char);
}
@ret;
}
$numSolutions = 0;
$target = 5;
@nums = qw/2 4 6 8 10/;
@perms = permutations("01234");
@ops = combinations("*/+-", "*/+-", "*/+-", "*/+-");
foreach $perm (@perms){
foreach $op (@ops){
@pToken = split(//, $perm);
@oToken = split(//, $op);
$exp = $nums[$pToken[0]] . $oToken[0] . $nums[$pToken[1]] . $oToken[1] .
$nums[$pToken[2]] . $oToken[2] . $nums[$pToken[3]] . $oToken[3] .
$nums[$pToken[4]];
if(eval($exp) == $target){
print "$exp = $target, ";
$numSolutions++;
}
}
}
print "$numSolutions solution(s) found...";
b.)
2/4*6-8+10 = 5, 2/4*6+10-8 = 5, 2*4/8-6+10 = 5, 2*4/8+10-6 = 5, 2*6/4-8+10 = 5, 2*6/4+10-8 = 5, 2/8*4-6+10 = 5, 2/8*4+10-6 = 5, 4*2/8-6+10 = 5, 4*2/8+10-6 = 5, 4+6/2+8-10 = 5, 4+6/2-10+8 = 5, 4/8*2-6+10 = 5, 4/8*2+10-6 = 5, 4+8+6/2-10 = 5, 4+8-10+6/2 = 5, 4-10+6/2+8 = 5, 4-10+8+6/2 = 5, 6*2/4-8+10 = 5, 6/2+4+8-10 = 5, 6*2/4+10-8 = 5, 6/2+4-10+8 = 5, 6/2+8+4-10 = 5, 6/2+8-10+4 = 5, 6/2-10+4+8 = 5, 6/2-10+8+4 = 5, 6/4*2-8+10 = 5, 6/4*2+10-8 = 5, 6-4+8-10/2 = 5, 6/4*10-2-8 = 5, 6-4-10/2+8 = 5, 6/4*10-8-2 = 5, 6+8-4-10/2 = 5, 6+8-10/2-4 = 5, 6-10/2-4+8 = 5, 6-10/2+8-4 = 5, 6*10/4-2-8 = 5, 6*10/4-8-2 = 5, 8/2/4-6+10 = 5, 8/2/4+10-6 = 5, 8/4/2-6+10 = 5, 8/4/2+10-6 = 5, 8+4+6/2-10 = 5, 8-4+6-10/2 = 5, 8-4-10/2+6 = 5, 8+4-10+6/2 = 5, 8+6/2+4-10 = 5, 8+6/2-10+4 = 5, 8+6-4-10/2 = 5, 8+6-10/2-4 = 5, 8-10/2-4+6 = 5, 8-10/2+6-4 = 5, 8-10+4+6/2 = 5, 8-10+6/2+4 = 5, 10+2/4*6-8 = 5, 10-2-4*6/8 = 5, 10+2*4/8-6 = 5, 10-2-4/8*6 = 5, 10+2*6/4-8 = 5, 10-2-6*4/8 = 5, 10-2-6/8*4 = 5, 10+2/8*4-6 = 5, 10+4*2/8-6 = 5, 10/4*6-2-8 = 5, 10/4*6-8-2 = 5, 10-4*6/8-2 = 5, 10+4/8*2-6 = 5, 10-4/8*6-2 = 5, 10+6*2/4-8 = 5, 10-6+2*4/8 = 5, 10-6/2-8/4 = 5, 10-6+2/8*4 = 5, 10*6/4-2-8 = 5, 10+6/4*2-8 = 5, 10-6+4*2/8 = 5, 10*6/4-8-2 = 5, 10-6*4/8-2 = 5, 10-6+4/8*2 = 5, 10-6+8/2/4 = 5, 10-6/8*4-2 = 5, 10-6+8/4/2 = 5, 10+8/2/4-6 = 5, 10-8+2/4*6 = 5, 10-8+2*6/4 = 5, 10+8/4/2-6 = 5, 10-8/4-6/2 = 5, 10-8+6*2/4 = 5, 10-8+6/4*2 = 5, 88 solutions found...
2005-03-19
Instrumental Searches
First off, a question: Would you want the power of Google in your brain?
Now for my post...
Have you ever noticed how hard it is to search for songs with no (or hardly any) lyrics on "teh intarweb"? Well, maybe if you're a n00b, searching for any song is tough... but yeah.
So anyway, there was this song I wanted to download that I had heard and most anyone over 21 has heard. It's kind of a disco-ish sounding song with a trumpet that you probably heard while shopping once. So, can you tell me the name of the song based on that description? Exactly, neither could Google. However, I knew that since I could basically "sing" (what do they call singing instrumental music?) this song, somebody would be able to tell me what is was called.
I was wrong. Nobody knew the title of my mystery song, even if they knew the tune...
Then, one day, a co-worker of mine heard me "singing" this disco-y tune (yes, I do that at work) and said something about "King of the Hill". Can you guess the name of the song yet... or at least the artist? Well, not unless you watch "King of the Hill" -- which I don't. This information, however, gave me something to google and presto!... I found first "Chuck Mangione" and then "Feels So Good": which happened to be the artist and song title! A groovy song indeed. Once I had this vital information it was easy enough to find and download it via WinMX.
The next song was even harder to find. Again, hardly any lyrics to go off of. I "sang" the instrumental song to the same co-worker who had heard a cheap rendition of it on "Saturday Night Live". He said something about a "Wake Up Wakefield!" skit they did on SNL with the band playing the song. From that I found that this band on the skit called "Jazz Times Ten" played the song I wanted as an introduction. From that, I found the title of the song, called "Pick Up The Pieces" from "Average White Band". That's what I call "lucky times ten".
Anyway, my point. I think the idea of being able to have the power of Google built right into my brain is intriguing; but only if I'll also be able to google someone else's brain.
2005-01-06
It sure is curious that some lyrics I transcribed from the exercise your choppers song would be so popular. From viewing the list of links people have followed to get to my site, the trend seems to be people typing part of the lyrics from that marvy commercial into a search engine and my site being at or near the top of the list. (Was that a run-on sentence, Mrs. Passmore?) Apparently, nobody (other than me) put the lyrics (of a song that many eyes and ears digested in the 80s of all things) on their site, so my page won by default.
So for all those who loved that commercial, I've done a little homework for you so you don't have to. I actually found the commercial on "teh intarweb" for your viewing pleasure:
Education, 80's Style!
This site not only has "The Chopper" song but a bunch of other cool ones I remember such as: "Time for Timer", "Beans and Rice", "Don't Drown Your Food" and many more. I also found "The Chopper" (and some others) posted on YouTube.
I know a lot of people really loved the Schoolhouse Rock commercials that came out around the same time (as well they should, 'cause they still are groovy), but these ABC Health and Nutrition Commercials should get more attention. I keep seeing overweight and obese children who don't get enough exercise and don't eat healthfully. I think they should put these commercials back on TV (Cartoon Network, perhaps) or even make new ones. The songs stuck with me (as well as the message.) My kids thought I was weird for watching old commercials but they have taken to them as well. Now my children sing "exercise your choppers" with me at the dinner table.