Programming Question - Combinations/Permutations

Off-topic chat, talk about whatever you like..
User avatar
admin
Senior Member
Posts: 1029
Joined: Fri Apr 29, 2005 6:44 pm

Post by admin »

No probs, enjoy a challenge!

An easy way of making this faster withought modding the code would be to use a dictionary containing only words between 3 and 8 letters.
User avatar
Matt Vinyl
Senior Member
Posts: 7198
Joined: Wed May 11, 2005 6:56 pm
Location: Lost in the outback, Bryan

Post by Matt Vinyl »

Yes, true - I may well cull my dictionary. Just import it into Access or something and do a bit of simple code to limit the list, then re-export it to txt.

Just reading through your code at the moment, and I think I should be alright converting it, may have to drop you a PM if I get stuck... ;)

EWQ - input much appreciated and interesting too! I've always craved a mathematical mind! ;)

:)
"And do you ever contradict yourself, Minister?" "Well, yes and no..."
Weyland
Senior Member
Posts: 1001
Joined: Fri Nov 18, 2005 9:58 pm

Post by Weyland »

Minor tip, but it might be worth generating your words and inserting them into a sorted list, and only then doing the "real word" check by stepping through that list as you step through your dictionary. Then you know that the next word in the list will be after your current place in the dictionary. That should save you a fair few random accesses into your dictionary, as you know you won't have to go backwards. (Will also help with memory cacheing too).

(Not read the source, so apologies if that's what you're doing already ;) )
Ernest W. Quality
Senior Member
Posts: 540
Joined: Wed Jun 29, 2005 4:08 pm
Location: Leedsish
Contact:

Post by Ernest W. Quality »

Along the same lines as Weyland, maybe have a separate dictionary file for each length of word, so you only check the 3-letter "words" with the three-letter dictionary.
Image
Bob
Junior Member
Posts: 14
Joined: Sat Apr 30, 2005 2:43 pm

Post by Bob »

Instead of working out all the possible combinations in the original word, and then checking them in the dictionary, you could do it the other way round -
Find each valid word (3-8 letters) in the dictionary, and then check if it's in the original word..
Bob
Junior Member
Posts: 14
Joined: Sat Apr 30, 2005 2:43 pm

Post by Bob »

Instead of working out all the possible combinations in the original word, and then checking them in the dictionary, you could do it the other way round -
Find each valid word (3-8 letters) in the dictionary, and then check if it's in the original word..
Weyland
Senior Member
Posts: 1001
Joined: Fri Nov 18, 2005 9:58 pm

Post by Weyland »

Basically, now is the time to experiment. ;) You probably won't know which is fastest until you try them...
User avatar
admin
Senior Member
Posts: 1029
Joined: Fri Apr 29, 2005 6:44 pm

Post by admin »

You can still use one word list, it just needs to be sorted from lowest number of letters to highest number of letters instead of alphabetically.

You then just need to know at which line 8 letter words start and finish (or any other number(s)), and adjust the loop to search between those lines only..
User avatar
admin
Senior Member
Posts: 1029
Joined: Fri Apr 29, 2005 6:44 pm

Post by admin »

New optimised version attatched.

Ive done away with a nested loop, and it also now only checks dictionary words between 3 and 8 letters.

Not as fast as I thought, but it is more than twice as fast as the origional.
Attachments
v2_139.zip
(368.44 KiB) Downloaded 51 times
User avatar
Matt Vinyl
Senior Member
Posts: 7198
Joined: Wed May 11, 2005 6:56 pm
Location: Lost in the outback, Bryan

Post by Matt Vinyl »

Ah, good stuff! Will take a look through this today! Hopefully, should have most of the game put together by the end of the coming week, so will upload a trial version here! ;)

Cheers for all your help!! ;) I just couldn't get my head around it at first! ;)

:)
"And do you ever contradict yourself, Minister?" "Well, yes and no..."
User avatar
Matt Vinyl
Senior Member
Posts: 7198
Joined: Wed May 11, 2005 6:56 pm
Location: Lost in the outback, Bryan

Post by Matt Vinyl »

Looking at the dictionary I've used, there are a lot of words that I wouldn't say were 'commonly used'. For example, 'Recipes' throws up this many 3 letter words:

cep cis ers ice ire per pes pic pie pis psi rec rei rep res rip sec sei ser sic sip sir sri

I know that quite a few of these are common, but some are a lot less 'familiar'. Sei, anyone?

I now may add another limitation that says the chosen 8 letter word (I know I used a 7-letter word for my example!) will only be included if the number of 3-letter words is also limited (to say 8 or 10). I know this will still pick up words that do contain a lot of obscure smaller words, but hey, it'll make it interesting! ;)

:)
"And do you ever contradict yourself, Minister?" "Well, yes and no..."
Cardinal Sin
Senior Member
Posts: 4166
Joined: Wed Jul 20, 2005 3:33 pm

Post by Cardinal Sin »

Sei is an obsolete spelling of say...

Barely a day goes by without me using it!
User avatar
Istenem
Senior Member
Posts: 5918
Joined: Sat Apr 30, 2005 2:42 pm
Location: the nation's capital
Contact:

Post by Istenem »

Matt Vinyl wrote: cep cis ers ice ire per pes pic pie pis psi rec rei rep res rip sec sei ser sic sip sir sri
yuck!

you might want to winnow out dross like that Matt. (i realise it is probably a big job.)
a. it devalues the integrity of a word game if non-words are accepted. don't get me started on scrabble but that allows far too many combinations of letters to pass for words.

b. it makes the game easier for deadheads who can just thrash out random combinations of letters and get lucky.

c. it becomes a game of learning rather than quickwittedness/skill

just my 2pworth.
nobody ever wins on those things.
Weyland
Senior Member
Posts: 1001
Joined: Fri Nov 18, 2005 9:58 pm

Post by Weyland »

A few more for you :) :

cep - An edible mushroom.
cis - Having two mutations on two genes on the same chromosome of a homologous pair.
ers - A vetch, grown in Europe for forage.
pes - A foot or footlike part. / The 17th letter of the Hebrew alphabet.
pis - The plural of Pi, the 16th letter of the Greek alphabet.
rei - A portuguese money of account, in value about one tenth of a cent.
sec - (of wines) Dry, not sweet.
sei - A sei whale.
ser - A unit of weight in India.
sri - A Hindu title of address prefixed to the name of a deity, holy person, etc.

I take your point about them reducing the skill required in a word game, particularly as regards to random button-bashing. But surely knowing lots of esoteric words is the point of being good at a word game? Yes, you should also know what the word means, and while that can be enforced on things like Countdown, it's harder to enforce on quiz boxes.

Maybe once you've entered a word you have to pic the meaning from a selection? I apperciate that there would still be a chance of randomly selecting the right answer, but no more than the average spoiler.
User avatar
Matt Vinyl
Senior Member
Posts: 7198
Joined: Wed May 11, 2005 6:56 pm
Location: Lost in the outback, Bryan

Post by Matt Vinyl »

All good points! :)

(Nice list Weyland!)

There are a few options, as suggested. I 'could' try and find a dictionary that is more limited. I 'could' allow the words to be used, but considerably limit the score of getting the three letter words. (Surely as I go up the 'letter scale' (4,5,6 etc.) the amount of non-words (that are included in the dictionary) would decrease?) (And how many brackets can I use in one sentence!?)

This has become far more involved that I thought it would! :)
"And do you ever contradict yourself, Minister?" "Well, yes and no..."
Locked