#!/usr/bin/perl ######################################### # The purpose of this program is to help # cheat at Scrabble. Ultimately though it's more # about the intellectual exercise of writing the # actual program. I've tried using it (on http://isc.ro) # and found that it's more work than it's worth. In fact, # once I tried it (I *nearly* (*cough*) always informed # my opponents beforehand) my rating quickly deteriorated. # # Also, I don't have the program on my phone so when I'm # out and about I show my true colors anyway. # # There's actual a little embarrassing anecdote here: # # I started a game (20 minutes, challenge: DOUBLE) at # home, full of confidence that I would beat my opponent # with the help of my litle program. Unfortunately, my # opponent wanted to adjourn due to some emergency. What # happened then was ofcourse that we continued the game # while I was driving a bus to work. Needless to say my # performance was noticeable sub-stellar. So bad, in fact, # that I had to come clean. Luckily for me he/she took it in # full stride enjoying serving me my head on a platter. :) # # sbrothy 21:26 9/9/2021 # ######################################### use autodie; use diagnostics; use strict; use warnings; use 5.010; use File::Fetch; my $ff = File::Fetch->new(uri => 'https://www.wordgamedictionary.com/sowpods/download/sowpods.txt' ); my $csw = $ff->fetch(to => '/tmp'); my @words; open my $fh, '<', $csw; foreach (<$fh>) { tr/\r\n//d; tr/\[A-Z]/[a-z]/; next if /\s+/; # dirty way of removing comments push @words, $_; } close $fh; ############################################ my $tiles = 'a.'; print "MATCHES FOR: $tiles\n"; my @m = find_matches($tiles); print "\n@m\n"; ############################################ $tiles = 's.'; print "MATCHES FOR: $tiles\n"; @m = find_matches($tiles); print "\n@m\n"; ############################################ sub find_matches { my $letters = shift; my $regex = join '', map "$_?", sort split //, $letters; my @matches; foreach my $word (@words) { if(join('', sort split //, $word) =~ /^$regex$/) { push @matches, $word; } } return @matches; }