paulhurley.co.uk

  • Increase font size
  • Default font size
  • Decrease font size
Home Geek Ubuntu Linux How to Cheat at Scramble

How to Cheat at Scramble

E-mail Print PDF
User Rating: / 3
PoorBest 

I've been on Facebook for a while, and like everyone else, I started playing scramble, a boggle like game.  Well, I'm not very good, and got tired of getting beat.  There must be an easier way !

In my professional life I support people using barcode scanners.  Now, the scanners we use now usualy pretend to be a keyboard over usb.  Older ones used serial communication and a piece of software called a 'wedge' to feed the input from the serial port to the keyboard, so I came up with the most complicated solution I could.  Our desktop PC running Windoze and a serial to keyboard wedge.  My Linux laptop would run a batch script and echo the results over a null modem cable to the Windows PC serial port where the text gets piped to the keyboard and plays the game.

Here's my script;

#!/bin/bash                    
#                              
# scramble2.sh                 
#                              
# This script generate 6,5,4 and 3 letter words
# from /usr/src/dict/words fro cheating at scramble
#                                                 
# Ver 2 of script, this one will try to build the list of possible
# two letter combinations that any word could start with, using an array !                                                                     
#                                                                      
# Usage: scramble.sh -l "letters"                                      
#                                                                      
# Created P Hurley   15 July 2008                                      
#                                                                      

#
#


usage="\nBatch script to cheat at scramble\n"
usage+="Basically, this script will extract all the 8,7,6,5,4 and 3 letter words from\n"                                                       
usage+="\t /usr/share/dict/words based on the letters provided and print them\n"                                                               
usage+="\tscramble.sh -l letters > device\n"                           

today=$(date +%Y%m%d)
current_path=`pwd`  

while getopts "l:" opt
do                   
case $opt in 

l  ) letters=$OPTARG ;;
\? ) echo -e $usage   
exit 1           
esac                          
done                                  
sleep 3                               
#echo $letters                        
#Output lists of words                

#########################################################################                                                                      
#setup com port                                                        
stty -F /dev/ttyS0 speed 2400                                          
stty -F /dev/ttyS0 speed 2400                                          

#########################################################################                                                                      
#Declare Arrays, variables and Constants                               
maxcols=5                                                              
maxrows=5                                                              


#########################################################################                                                                      
#Begin Loop                                                            
declare -a Arletters                                                   
declare -a Arpossibles                                                 
pipey="\|"                                                             
row=4                                                                  
# Read in letters into ArLetters                                       
lenlet=${#letters}      # number of letters submitted                  
for ((pos=0;pos
arletters[pos]=${letters:pos:1}       #read the letters into the arletters array                                                             
if [ ${arletters[pos]} = "q" ]; then                                 
arletters[pos]="qu"                                                
fi                                                                   
done                                                                   
row=$(echo -e "sqrt($lenlet)\nquit\n"|bc -q -i)         #find row length by sqruare root of num letters                                        
#echo "${arletters[@]}"                                                
#echo $lenlet                                                          
#echo $row                                                             
#######   Start main loop                                              
n=0     # count number of possible combinations                        
for ((y=1; y
for ((x=1; x
for ((dx=-1; dx<2; dx++)); do             #change in columns     
for ((dy=-1; dy<2; dy++)); do #change in rows                
tempcol=$[ $x + $dx ]                                      
temprow=$[ $y + $dy ]                                      
arrayindex1=$[ $x + ( $row * ( $y - 1 ) ) - 1 ]            
arrayindex2=$[ $tempcol + ( $row * ( $temprow - 1 ) ) - 1 ]
#           echo "Column "$x", Row "$y" arraynum "$arrayindex1" "$arrayindex2".Letter "${arletters[$arrayindex1]}". Square "$tempcol" by "$temprow" letter "${arletters[arrayindex2]}                                  
if [ $tempcol -gt 0 ]; then                              
if [ $temprow -gt 0 ]; then                            
if [ $tempcol -ne $x -o $temprow -ne $y ]; then      
if [ $temprow -lt $row ];then                    
if [ $tempcol -lt $row ];then                  
#                         echo "Hit: arpossibles["$n"] will be "${arletters[arrayindex1]}${arletters[arrayindex2]}                             
arpossibles[n]="${arletters[arrayindex1]}${arletters[arrayindex2]}"                                                  
n=$[ $n + 1 ]                                
fi                                                 
fi                                                   
fi                                                     
fi                                                       
fi                                                         
done                                                         
done                                                           
done                                                             
done                                                               
#echo $n                                                               
#echo "${arpossibles[@]}"                                              
############  build searchstring                                       
searchstring="${arpossibles[0]}"                                       
for ((l=1; l<$n; l++)); do                                             
#  echo $l" is "${arpossibles[l]}                                      
searchstring="$searchstring$pipey${arpossibles[l]}"                  
done                                                                   
#debug  echo $searchstring                                             
################ do the searches                                       
#This reads out the standard dictionary, pipes it to grep to do the search                                                                     
#and then pipes that through sed to replace the newlines with several new                                                                      
#lines and a '1' ona  line of it's own.  The barcode wedge will turn the 1                                                                     
#into a hard newline to try to stop it getting confused                

cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"  | sed 's/.$/&\n\n\n1\n/g'       # 10 letter words                              
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'  # 9 letter words                                               
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'   # 8 letter words                                                        
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'      # 7 letter words                                                               
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'        # 6 letter words
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'  # 5 letter words               
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters][$letters]$" | sed 's/.$/&\n\n\n1\n/g'    # 4 letter words                       
cat /usr/share/dict/words | grep "^\($searchstring\)[$letters]$" | sed 's/.$/&\n\n\n1\n/g'      # 3 letter words                               

#Do word counts
ten=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`# 10 letter words                                                       
nine=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`  # 9 letter words                                                               
eight=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters][$letters]$"`   # 8 letter words
seven=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters][$letters][$letters]$"`     # 7 letter words       
six=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters][$letters]$"` # 6 letter words                       
five=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters][$letters]$"`  # 5 letter words                               
four=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters][$letters]$"`    # 4 letter words                                       
three=`cat /usr/share/dict/words | grep -c "^\($searchstring\)[$letters]$"`     # 3 letter words                                               

echo "scramble2.sh,"$letters","$ten","$nine","$eight","$seven","$six","$five","$four","$three
echo "scramble2.sh,"$letters","$ten","$nine","$eight","$seven","$six","$five","$four","$three >> scramble.txt
#debug  echo "^$searchstring[$letters][$letters][$letters][$letters][$letters][$letters]$"

# comparison for older script
ten=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`      # 10 letter words
nine=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`      # 9 letter words
eight=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`        # 8 letter words
seven=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"`  # 7 letter words
six=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters][$letters]$"`      # 6 letter words
five=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters][$letters]$"`       # 5 letter words
four=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters][$letters]$"` # 4 letter words
three=`cat /usr/share/dict/words | grep -c "^[$letters][$letters][$letters]$"`  # #3 letter words
echo "scramble.sh,"$letters","$ten","$nine","$eight","$seven","$six","$five","$four","$three
echo "scramble.sh,"$letters","$ten","$nine","$eight","$seven","$six","$five","$four","$three >> scramble.txt
#echo "^[$letters][$letters][$letters][$letters][$letters][$letters][$letters][$letters]$"

echo $letters >> letters.txt
Comments (3)
3 Thursday, 24 November 2011 08:25
Pittsburgh Steelers Jerseys
Cheap Steelers Jerseys
Authentic Steelers Jerseys
Kids Steelers Jerseys
coach outlet store online
coach outlet online
Coach Crossbody
Coach Backpack
Coach Diaper Bags
supra skytop
purple shoes
supra skytop purple
"it is released by pittsburghsteelersjerseyssale.com 2011.11.24"
Welcome to our online shop to choose your favorite team and player’s jersey.
Pittsburgh Steelers Jerseys
Cheap Steelers Jerseys
Ben-Roethlisberger-Jersey
Heath-Miller-Jersey
Authentic James Harrison Jersey
Troy Polamalu Jersey
Authentic Steelers Jerseys
Steelers Super Bowl Jerseys
Steelers Women's Jerseys
Kids Steelers Jerseys
Authentic Eagles Jerseys
Cheap Eagles Jerseys
Authentic Vick Jersey
LeSean McCoy Jerseys
Authentic Young Jersey
Custom Eagles Jerseys
Official Philadelphia Eagles Jersey
Authentic Eagles Throwback Jerseys
Cheap Steelers Jerseys
Steelers Jersey
Steelers Throwback Jerseys
Cheap Womens Steelers Jersey
Cheap Youth Steelers Jersey
roethlisberger jersey
Polamalu Jersey
Cheap heath miller jersey
Coach Outlet Store Online
Coach Outlet
Coach Backpack
Coach Diaper Bags
Coach Tote Bags
Coach Poppy
We encourage you to join our club loyalty, started saving up money for the team's gear, and visit us again every time you want to buy some show you the pride of the team. Shop player
"it is released by pittsburghsteelersjerseyssale.com 2011.12.13"
comment
2 Friday, 27 March 2009 19:22
here's a comment

Add your comment

BoldItalicUnderlineStrikethroughSubscriptSuperscriptEmailImageHyperlinkOrdered listUnordered listQuoteCodeHyperlink to the Article by its id
Very HappySmileWinkSadSurprisedShockedConfusedCoolLaughingMadRazzEmbarrassedCrying or Very SadEvil or Very MadTwisted EvilRolling EyesExclamationQuestionIdeaArrowNeutralMr. GreenGeekUber Geek
Your name:
Your email:
Your website:
Subject:
Comment:
 

Who's Online

We have 2 guests online

Login Form

Members : 5
Content : 62
Web Links : 7
Content View Hits : 130095

last.fm Playlist

Recent Tracks:

Recent Comments, category: "Ubuntu Linux"