Skip to content
zelf0 edited this page Aug 6, 2021 · 2 revisions

The way the program works is by randomly shuffling an array containing the letters of the alphabet. Then, the letters are plugged into "cards" which are the words that will end up in the chain. The letters are assigned to variables which are inserted into the cards, like so:

`sprintf(card[0], "%c%c%c%c%c", a, b, c, d, e);`
`sprintf(card[1], "%c%c%c%c%c", a, l, m, n, o);`
`sprintf(card[2], "%c%c%c%c%c", s, e, i, l, v);`
`sprintf(card[3], "%c%c%c%c%c", i, d, w, p, m);`
`sprintf(card[4], "%c%c%c%c%c", b, h, n, s, w); `
`sprintf(card[5], "%c%c%c%c%c", a, f, g, h, i);`
`sprintf(card[6], "%c%c%c%c%c", a, u, v, w, y);`
`sprintf(card[7], "%c%c%c%c%c", b, f, l, p, u);`
`sprintf(card[8], "%c%c%c%c%c", b, g, m, r, v);`
`sprintf(card[9], "%c%c%c%c%c", a, p, r, s, t);`
`sprintf(card[10], "%c%c%c%c%c", b, i, o, t, y); `
`sprintf(card[11], "%c%c%c%c%c", s, c, f, m, y);`
`sprintf(card[12], "%c%c%c%c%c", s, d, g, o, u);   `
`sprintf(card[13], "%c%c%c%c%c", u, m, e, t, h);  `
`sprintf(card[15], "%c%c%c%c%c", p, h, o, v, c);`
`sprintf(card[14], "%c%c%c%c%c", i, c, u, r, n);`
`sprintf(card[16], "%c%c%c%c%c", y, d, h, l, r);`
`sprintf(card[17], "%c%c%c%c%c", p, g, e, y, n);`
`sprintf(card[18], "%c%c%c%c%c", o, e, f, r, w);`
`sprintf(card[19], "%c%c%c%c%c", w, c, g, l, t);`
`sprintf(card[20], "%c%c%c%c%c", v, f, d, n, t);`

All 21 cards (13 in the four-letter version) now contain a list of strings which follow the rule, which is that each string has precisely one character in common with every other string. Then, the cards are checked one by one to see if the string (or any permutation of the string) is actually a valid English word. If a card fails the check, the letters are reshuffled and plugged into the cards.

Version 1: Simply checks using binary search on an array of English words, and reshuffles as soon as a card fails the check.

Version 2: Checks using binary search on an array of English words. This time, if a card fails the check and there are already valid cards in the set, one extra character is added to the string and it is re-checked to see if it's a valid English word. So in the five-letter version, there are 21 letters used in the cards, so the remaining 5 letters can be added to a word as an extra character. It doesn't affect the rule, since the letter is unique to this card.

Version 3: Adds file that uses a hash table to store the English words instead of an array.

Version 4: Adds a file that uses a trie to store the English words instead of an array or hash table. Trie is the most efficient, then hash table, then array.

Version 5: Instead of shuffling all 26 letters, it only shuffles 23 letters and Q, X, and Z are automatically excluded from the cards. Any set with Q will be invalid since two words won't have only Q in common, both would also have U. Z and X also decrease the likelihood of a valid set, so it's more efficient to only use sets that don't contain these letters. These letters are still used as an extra character to be added to cards that fail the initial check.

Clone this wiki locally