Click here to Skip to main content
15,911,762 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: modulus. need help (visual c++) Pin
PICguy4-Jan-07 16:41
PICguy4-Jan-07 16:41 
QuestionHardware serial encryptor/decryptor Pin
Cyclone0217-Oct-06 19:03
Cyclone0217-Oct-06 19:03 
AnswerRe: Hardware serial encryptor/decryptor Pin
tydok18-Oct-06 3:03
tydok18-Oct-06 3:03 
GeneralRe: Hardware serial encryptor/decryptor Pin
Cyclone0218-Oct-06 3:27
Cyclone0218-Oct-06 3:27 
AnswerRe: Hardware serial encryptor/decryptor Pin
El Corazon18-Oct-06 6:00
El Corazon18-Oct-06 6:00 
GeneralRe: Hardware serial encryptor/decryptor Pin
Cyclone0219-Oct-06 4:02
Cyclone0219-Oct-06 4:02 
GeneralRe: Hardware serial encryptor/decryptor Pin
El Corazon19-Oct-06 4:07
El Corazon19-Oct-06 4:07 
Questionhow to make a faster algorithm Pin
roberto_santinni17-Oct-06 11:12
roberto_santinni17-Oct-06 11:12 
Hey guys, please help?
I'm trying to count each character's occurance in a text. This is what I have but if I am working with 20,000 chars it takes forever. How can I make it faster? (Especially the nested for loop)

Thanks a lot!

<code>private void frequencyItem_Click(object sender, System.EventArgs e)
{
Form3 form3 = new Form3(); //creating new form that tells the user to please wait...
form3.Show(); //displays the form3

cipherTxt.Text = "";
float numTimes = 0; //declaring and initializing numTimes which stores the number of times a char is presented
//declaring and initializing my 72 char alphabet
String myAlphabet = new String(new char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9','\u0027','\u002E','\u002C','\u003A','\u003B','\u003F','\u0021','\u0023','\u0028','\u0029'});

//nested for loop comparing every char in the alphabet to every char in the plaintext textbox
for(int i=0;i<myAlphabet.Length;i++)
{
for(int j=0;j<plainTxt.Text.Length;j++)
{
if(plainTxt.Text[j] == myAlphabet[i]) //if a plaintext char matches an alphabet char
{
numTimes++; //increase count for numTimes
}
}
if(numTimes>0) //if number of times a char's ocurrence is presented
{
//print in ciphertext textbox the result of percentages
cipherTxt.Text += "Letter " + myAlphabet[i] + " is displayed "
+ numTimes + " times. It is " + (numTimes/plainTxt.Text.Length)*100 + "% of the whole text." + System.Environment.NewLine;
}

numTimes = 0; //return the current alphabet's char count to 0
}
string frequencyLetters = cipherTxt.Text; //pass results to a string
cipherTxt.Text = ""; //clear ciphertext textbox
form3.Close(); //closes the waiting form...
try //tries following block of code if user selects Cancel on save box
{
saveFileDialog.ShowDialog(); //show the save dialog
String saveFileName = saveFileDialog.FileName; //store output filename as string
TextWriter textOut = new StreamWriter(saveFileName); //new streamwriter to filename
textOut.WriteLine(frequencyLetters); //writing results to file
textOut.Close(); //closing streamwriter
}
catch(Exception arg) //catches exception
{
return; //exits void function
}

}</code>

Santinni
AnswerRe: how to make a faster algorithm Pin
ejuanpp17-Oct-06 12:27
ejuanpp17-Oct-06 12:27 
JokeRe: how to make a faster algorithm Pin
toxcct17-Oct-06 12:46
toxcct17-Oct-06 12:46 
AnswerRe: how to make a faster algorithm Pin
Haoman1718-Oct-06 1:17
Haoman1718-Oct-06 1:17 
GeneralRe: how to make a faster algorithm Pin
peterchen21-Oct-06 12:27
peterchen21-Oct-06 12:27 
GeneralRe: how to make a faster algorithm Pin
Haoman1722-Oct-06 7:58
Haoman1722-Oct-06 7:58 
AnswerRe: how to make a faster algorithm Pin
Rob Graham21-Oct-06 13:52
Rob Graham21-Oct-06 13:52 
AnswerRe: how to make a faster algorithm Pin
Xint026-Oct-06 16:50
Xint026-Oct-06 16:50 
QuestionWhat is the 13th root of . . . Pin
Bassam Abdul-Baki17-Oct-06 3:59
professionalBassam Abdul-Baki17-Oct-06 3:59 
QuestionHow to draw thick lines using Bresenham's Algorithm? Pin
Arun Chakaravarthy16-Oct-06 23:28
Arun Chakaravarthy16-Oct-06 23:28 
QuestionRUNGE-KUTTA ALGORITH FOR SECOND-ORDER ODE Pin
sahoong15-Oct-06 6:58
sahoong15-Oct-06 6:58 
AnswerRe: RUNGE-KUTTA ALGORITH FOR SECOND-ORDER ODE Pin
franky_mp31-Oct-06 1:48
franky_mp31-Oct-06 1:48 
QuestionTidal elevation calculation Pin
El Corazon12-Oct-06 11:47
El Corazon12-Oct-06 11:47 
AnswerRe: Tidal elevation calculation Pin
Dan Neely13-Oct-06 2:29
Dan Neely13-Oct-06 2:29 
GeneralRe: Tidal elevation calculation Pin
El Corazon13-Oct-06 3:17
El Corazon13-Oct-06 3:17 
GeneralRe: Tidal elevation calculation Pin
Dan Neely13-Oct-06 3:36
Dan Neely13-Oct-06 3:36 
GeneralRe: Tidal elevation calculation Pin
El Corazon13-Oct-06 3:46
El Corazon13-Oct-06 3:46 
AnswerRe: Tidal elevation calculation Pin
fat_boy7-Nov-06 1:16
fat_boy7-Nov-06 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.