Thanks Charles for the great suggestions. I will implement your suggestions but am still curious as to why my code doesn't work. Without ordering the list or starting the first word elsewhere, the one solution I am aware of for these 16 words has the word "QUANTITY" top left - hence my reasoning for trying this. I am not sure if standard crosswords always have the first word top left or not.
Anyway as Paul Andrews suggests, my algorithm must be incorrect so I need to go through this with a fine tooth comb and see where any why it is failing. Thanks for your advice Paul -----Original Message----- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Charles Parcell Sent: 31 May 2009 15:19 To: Flash Coders List Subject: Re: [Flashcoders] Crossword generator advice Two suggestions. 1) Order your list of words from longest to shortest. Longer words have more letters to build off of for future word placement. Longer words are also harder to place within the grid size as additional words are added. 2) Starting your first word in the upper left limits how additional words are chained off of it. Specifically, you are limiting the generator to only matching the first letter of the second word to be placed. As an alternative you could place your first word (horizontally or vertically, try both) in the middle of your grid. This will allow for middle letters to be matched with the first word. Even better would be to have a floating grid. Start placing words allowing the range of X and Y to adjust but maintaining the maximum X and Y of your target grid. For example, lets say your first word is 8 characters long and your second word is 8 characters long as well. Your second word would cross the first word at position 5 or the first word and position 2 of the second word. Now if the first word were placed in the top left or the middle of the 9x9 grid, this match is not possible. If your generator could shift to allow for these words to fit within the constraints of your 9x9 range, you would be more likely to find a larger range of possible board layouts. In the case above, lets say the first word was placed horizontally in the middle of the grid on row 5. The result would be that the starting word would slide from row 5 up to row 3 to allow the second word to run from row 2 through row 9. Obviously this sliding around the grid would likely only happen within the first 2-6 placements (assuming that you were placing longer words first). By this point your would run out of range to slide your grid around. Meaning you would have met your X and Y bounds by sliding around your grid. Charles P. On Sun, May 31, 2009 at 7:36 AM, Paul Andrews <p...@ipauland.com> wrote: > I suspect that the algorithm is wrong. > > For example quantity top left, alb will only fit quantity in one place and > there is only one other "a" candidate "amble". Very quickly your choices > will be reduced due to placement, so 5,000 attempts seems excessive. > > Sadly I have a ton of other things to do or I'd have a go myself. > > Paul > ----- Original Message ----- From: "Paul Steven" < > paul_ste...@btinternet.com> > To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com> > Sent: Sunday, May 31, 2009 12:17 PM > > Subject: RE: [Flashcoders] Crossword generator advice > > > Thanks Paul >> >> My code should backtrack in the situation you mention. So for example if >> it >> fits tarragon on the first "t" but then continues to not be able to find a >> solution with tarragon in this position, it will backtrack so that it >> changes "tarragon" to the second "t". However I still can't find a >> solution >> with 16 words. There may be some other flaws in my logic preventing this. >> I >> was wondering if in order to find a solution it will take thousands of >> attempts to find a solution? I have a counter that when reaches 5000, it >> breaks out of the loop trying to find the solution so I am effectively >> trying 5000 combinations - perhaps there is an equation to calculate how >> many combinations there are? >> >> I would be interested if anyone else can solve this puzzle with an >> alternative crossword generator? >> >> Thanks >> >> Paul >> >> -----Original Message----- >> From: flashcoders-boun...@chattyfig.figleaf.com >> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul >> Andrews >> Sent: 31 May 2009 12:07 >> To: Flash Coders List >> Subject: Re: [Flashcoders] Crossword generator advice >> >> There is a flaw in your logic. >> >> It may be that multiple words fit a given situation, and so it's >> necessary >> (with such a simple algorithm) to backtrack and look for another word to >> fit >> >> once you are unable to fit another word from your list - so the real >> problem >> >> is saving where you are in the list of possible combinations as you go >> along. >> >> For example, in quantity there are two "t" s, so there are two >> possibilities >> >> for fitting a word. You may go with tarragon for the first "t" but in >> practice it may only be possible to have a solution with tarragon as the >> second "t". You must be able to backtrack your choice of tarragon as a >> solution for the first "t" and go with "twin" instead. You must be able to >> do this at every stage. Once you can your software should work. >> >> Paul >> >> >> ----- Original Message ----- From: "Paul Steven" < >> paul_ste...@btinternet.com> >> To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com> >> Sent: Sunday, May 31, 2009 10:09 AM >> Subject: RE: [Flashcoders] Crossword generator advice >> >> >> Just to add more information to how I am currently trying to achieve >>> this. >>> >>> I basically start with the first word in the list and place it in the top >>> left position 0,0. I then attempt to add the next word in the list by >>> finding a character in the first word that is the same as one of the >>> characters in this new word. If it fails to add this next word, it puts >>> this >>> word to the back of the list and tries the next word. If at any point, it >>> is >>> no longer able to add one of the remaining unplaced words, it back tracks >>> and changes the previously added word to a different one. So in theory it >>> should attempt to find a solution by trying every single word in the top >>> left 0,0 position, then attempting to add the others where they can fit. >>> The >>> complete crossword solution has the word "Quantity" in the top left going >>> across so in theory a solution should be possible with this word at this >>> position and this orientation. >>> >>> Hopefully someone can shed some light on a solution. >>> >>> Many thanks >>> >>> Paul >>> >>> -----Original Message----- >>> From: flashcoders-boun...@chattyfig.figleaf.com >>> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul >>> Steven >>> Sent: 31 May 2009 10:02 >>> To: 'Flash Coders List' >>> Subject: [Flashcoders] Crossword generator advice >>> >>> I am creating a crossword generator where you can enter the size of the >>> grid >>> and a list of words but for the life of me cannot get it to generate a >>> puzzle with all the words in my list. This list of words is from a >>> crossword >>> that I know is possible. Now either my generator is not up to scratch or >>> the >>> process of creating a crossword is very complex and will require so many >>> iterations that it would take a long time to work out a solution. >>> >>> Here is the list of words I am trying to generate the crossword with. The >>> size of the grid is 9 x 9. I have tried several online crossword >>> generators >>> and none of them are able to generate a puzzle of this size with these >>> words. The most words I have been able to generate a puzzle with is 11 >>> words. However I know for a fact it is possible as I have an actual >>> crossword with these 16 words. I would therefore appreciate any advice. >>> Perhaps someone has a crossword generator they can try these 16 words in? >>> >>> quantity >>> alb >>> iliad >>> epee >>> jinx >>> glass >>> inn >>> tarragon >>> quake >>> amble >>> twin >>> yearn >>> pilot >>> icing >>> xenon >>> user >>> >>> Thanks in advance >>> >>> Paul >>> >>> _______________________________________________ >>> Flashcoders mailing list >>> Flashcoders@chattyfig.figleaf.com >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>> >>> _______________________________________________ >>> Flashcoders mailing list >>> Flashcoders@chattyfig.figleaf.com >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>> >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders