0 Members and 2 Guests are viewing this topic.
abc...aaabacad...bce...
int N = max_word_length;int *A = malloc (sizeof (int) * N);char c;int i;while (1) {A[i] = (A[i]+1)%(26+61);}
Well, it was pseudo-code more than anything else.
#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){ int N = 200; int *A = malloc (sizeof (int) * N); char c; int i; while (1) { A[i] = (A[i]+1)%(26+61); } return 0;}
#include <iostream>#include <string>using namespace std;int main(int argc, char *argv[]);int main(int argc, char *argv[]){ string all_chars = "abcdefghijklmnopqrstuvwxyz"; int i, u; string finalString; for (i=0; i<26; i++) { for (u=0; u<26; u++) { finalString.append( all_chars.substr(i,1) ); finalString.append( all_chars.substr(u,1) ); cout << finalString << endl; } } return 0;}
aaaaabaaabacaaabacadaaabacadaeaaabacadaeafaaabacadaeafagaaabacadaeafagahaaabacadaeafagahaiaaabacadaeafagahaiajaaabacadaeafagahaiajakaaabacadaeafagahaiajakalaaabacadaeafagahaiajakalamaaabacadaeafagahaiajakalamanaaabacadaeafagahaiajakalamanaoaaabacadaeafagahaiajakalamanaoapaaabacadaeafagahaiajakalamanaoapaqaaabacadaeafagahaiajakalamanaoapaqaraaabacadaeafagahaiajakalamanaoapaqarasaaabacadaeafagahaiajakalamanaoapaqarasataaabacadaeafagahaiajakalamanaoapaqarasatau
The string length shouldn't be increasing that quickly. You should be getting a, b, c, d, ..., x, y, z, aa, ab, ac, ad, ..., zx, zy, zz, aab, etc...
Instead of an array, try something else. If you are kinda good with number systems, think of it this way. You have a base 26 number. If you have a function that converts that number into the correct string, then you just have to constantly increase the number by 1 each time.
#include <iostream>#include <algorithm>#include <vector>#include <iterator>#include <fstream> using namespace std; int main(){ string all_chars_string = "abcdefghijklmnopqrstuvwxyz"; vector<string> all_chars; int i; for (i=0; i<all_chars_string.length(); i++) { all_chars.push_back( all_chars_string.substr(i, 1) ); } /* Write words to the file */ ofstream myfile; myfile.open ("words.txt"); for (i=0; i<all_chars_string.length(); i++) { while ( next_permutation(all_chars.begin(), ( all_chars.end() - (all_chars_string.length()-i) ) ) ) { copy(all_chars.begin(), ( all_chars.end() -(all_chars_string.length()-i) ) , ostream_iterator<string>(myfile,"")); myfile << "\n"; cout << endl; } } myfile.close(); return 0;}
:ClrHome:For(A,0,7:Disp " //No spaces, just a quote:End:1->B:1->C:Delvar L1 16->dim(L1 //Omit the space between 'L1' and the '1' of "16" when typing on actual calc:Repeat getKey or B=17:If C:1+L1(B->L1(B:For(A,1,B:Output(8,A,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",L1(A),1:End:If 26=L1(B:Then:While 26=L1(max(1,A-1:A-1->A:1->L1(A:End:If A=1:Then:B+1->B:Else:DelVar C1+L1(A-1->L1(A-1:End:End:End
#include <stdio.h>void displayWord(unsigned long long word, int n) { char* buffer = malloc(n+1); buffer[n] = '\0'; while (n) { buffer[--n] = word%26 + 'A'; word /= 26; } printf("%s\n", buffer); free(buffer);}int main(){ int length = 1; unsigned long long word = 0; unsigned long long limit = 26; while (1) { displayWord(word++, length); if (word == limit) { word = 0; length++; limit *= 26; } }}