Click here to Skip to main content
15,886,018 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Richard MacCutchan7-Sep-20 22:38
mveRichard MacCutchan7-Sep-20 22:38 
GeneralRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Richard Deeming7-Sep-20 23:59
mveRichard Deeming7-Sep-20 23:59 
AnswerRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Dave Kreskowiak8-Sep-20 6:46
mveDave Kreskowiak8-Sep-20 6:46 
GeneralRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Richard Andrew x6422-Sep-20 10:36
professionalRichard Andrew x6422-Sep-20 10:36 
GeneralRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Dave Kreskowiak22-Sep-20 16:25
mveDave Kreskowiak22-Sep-20 16:25 
AnswerRe: My implementation of Eratosthenes sieve is horribly slow. But why? Pin
Patrice T18-Sep-20 19:51
mvePatrice T18-Sep-20 19:51 
QuestionHow can I remove alternate words from a sentence? Pin
maicart5-Sep-20 22:27
maicart5-Sep-20 22:27 
AnswerRe: How can I remove alternate words from a sentence? Pin
Gerry Schmitz6-Sep-20 4:14
mveGerry Schmitz6-Sep-20 4:14 
It doesn't work because the last sample has an "even" number of words. The "last word" would have to be the last 2 words (due to "alternating"). Nothing to do with "the".

This adds the "last 2 words" if the word count is even.
C#
string sentence = "It is not the entrance, it is the other exit.";

var words = sentence.Split( new char[] { ',', '.', ' ' }, StringSplitOptions.RemoveEmptyEntries );
List<string> selected = new List<string>();

for ( int i = 0; i < words.Length; i++ ) {
   if ( ( i + 1 ) % 2 > 0 ) {
      selected.Add( words[ i ] );
   }
}  // end for.

if ( words.Length > 1 && words.Length % 2 == 0 ) {
   selected.Add( words.Last() );
}

string result = string.Join( " ", selected );

Console.WriteLine( sentence );
Console.WriteLine( result );
Console.ReadKey();
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food


modified 6-Sep-20 12:46pm.

GeneralRe: How can I remove alternate words from a sentence? Pin
Richard MacCutchan6-Sep-20 6:13
mveRichard MacCutchan6-Sep-20 6:13 
GeneralRe: How can I remove alternate words from a sentence? Pin
Gerry Schmitz6-Sep-20 6:33
mveGerry Schmitz6-Sep-20 6:33 
AnswerRe: How can I remove alternate words from a sentence? Pin
Richard MacCutchan6-Sep-20 4:52
mveRichard MacCutchan6-Sep-20 4:52 
GeneralRe: How can I remove alternate words from a sentence? Pin
maicart6-Sep-20 6:23
maicart6-Sep-20 6:23 
GeneralRe: How can I remove alternate words from a sentence? Pin
Richard MacCutchan6-Sep-20 6:41
mveRichard MacCutchan6-Sep-20 6:41 
GeneralRe: How can I remove alternate words from a sentence? Pin
Richard Andrew x646-Sep-20 8:04
professionalRichard Andrew x646-Sep-20 8:04 
GeneralRe: How can I remove alternate words from a sentence? Pin
maicart7-Sep-20 1:27
maicart7-Sep-20 1:27 
GeneralRe: How can I remove alternate words from a sentence? Pin
Richard MacCutchan7-Sep-20 1:38
mveRichard MacCutchan7-Sep-20 1:38 
Questionalgorithm to place N rectilinear blocks in a ring to minimize total area Pin
rbuchana14-Aug-20 5:21
rbuchana14-Aug-20 5:21 
GeneralRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
harold aptroot14-Aug-20 8:04
harold aptroot14-Aug-20 8:04 
GeneralRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
rbuchana14-Aug-20 8:19
rbuchana14-Aug-20 8:19 
AnswerRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
Gerry Schmitz14-Aug-20 8:22
mveGerry Schmitz14-Aug-20 8:22 
AnswerRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
Greg Utas14-Aug-20 8:52
professionalGreg Utas14-Aug-20 8:52 
GeneralRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
rbuchana15-Aug-20 9:00
rbuchana15-Aug-20 9:00 
GeneralRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
Greg Utas15-Aug-20 9:36
professionalGreg Utas15-Aug-20 9:36 
GeneralRe: algorithm to place N rectilinear blocks in a ring to minimize total area Pin
Greg Utas15-Aug-20 9:45
professionalGreg Utas15-Aug-20 9:45 
QuestionArea vs perimeter Pin
ZhanatanFleming11-Aug-20 4:07
ZhanatanFleming11-Aug-20 4:07 

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.