Quick Search


Tibetan singing bowl music,sound healing, remove negative energy.

528hz solfreggio music -  Attract Wealth and Abundance, Manifest Money and Increase Luck



 
Your forum announcement here!

  Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums > Free Advertising Forums Directory > General Free Advertising Forums

General Free Advertising Forums This is a list of general free advertising forums. Also referred to as free classfied ad forums.

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-09-2011, 04:31 PM   #1
there803
 
Posts: n/a
Default language agnostic - Adjacent number algorithm grou

By which I imply this:

Given the input set of numbers:

1,two,three,four,5 gets to be "1-5".

1,2,Keyfinder Magical Jelly Bean.html,3,five,Office Professional Plus 2007 Sale,seven,nine,10,eleven,12,14 will become "1-3, five,Office 2007 Professional Key, seven,Microsoft Office Professional Plus 2010 Key, 9-12, 14"

This will be the very best I managed to come up with: [C#]

Which feels somewhat sloppy to me, so the concern is, is there somehow more readable and/or elegant solution to this?

public static string[] FormatInts(int[] ints)
{ if (ints == null) throw new ArgumentNullException("ints"); // hey what are you doing? if (ints.Length == 0) return new string[] ""; // absolutely nothing to process if (ints.Length == one) return new string[] ints[0].ToString(); // nothing to method Array.Sort<int>(ints); // need to sort these lil' babies List<string> values = new List<string>(); int lastNumber = ints[0]; // start with the first number int firstNumber = ints[0]; // same as above for (int i = one; i < ints.Length; i++) { int current = ints[i]; int difference = (lastNumber - current ); // compute difference between last number and current number if (difference == -1) // the numbers are adjacent { if (firstNumber == 0) // this is the first of the adjacent numbers firstNumber = lastNumber; else // we're somehow in the middle or at the end of the adjacent number set lastNumber = current; continue; } else { if (firstNumber > 0 && firstNumber ,Office Home And Business Product Key!= lastNumber) // get ready to print a set of numbers { values.Add(string.Format("0-1",microsoft office standard 2007 key, firstNumber, lastNumber)); firstNumber = 0; // reset } else // print a single value { values.Add(string.Format("0", lastNumber)); } } lastNumber = current; } if (firstNumber > 0) // if theres anything left, print it out { values.Add(string.Format("0-1", firstNumber, lastNumber)); } return values.ToArray();
}
  Reply With Quote

Sponsored Links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 09:54 AM.

 

Powered by vBulletin Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Free Advertising Forums | Free Advertising Message Boards | Post Free Ads Forum