|
Two more candidates for the beauty contest:
Candidate One:
private Random newRandom = new Random();
private List<int> MakeShuffledList1(int nItems)
{
return Enumerable.Range(1, nItems).ToList().OrderBy(item => newRandom.Next()).ToList();
}
List<int> newList = MakeShuffledList1(10);
Candidate Two:
private Random newRandom = new Random();
private List<int> MakeShuffledList2(int nItems)
{
List<int> shuffleList = Enumerable.Range(1, nItems).ToList();
List<int> resultList = new List<int>();
int currentValue;
while (shuffleList.Count > 0)
{
currentValue = shuffleList[newRandom.Next(0, shuffleList.Count - 1)];
resultList.Add(currentValue);
shuffleList.Remove(currentValue);
}
return resultList;
} This follows the usual beauty pageant drill: when Miss/Mr. Whatever is crowned, you know he/she will not be in the next selection category.
Test:
List<List<int>> bunchOLists = new List<List<int>>();
for (int i = 0; i < 10; i++)
{
bunchOLists.Add(MakeShuffledList1(5));
bunchOLists.Add(MakeShuffledList2(5));
}
bool IsDuplicate = false;
List<int> currentList;
for (int i = 0; i < bunchOLists.Count - 1; i++)
{
currentList = bunchOLists[i];
for (int j = 0; j < bunchOLists.Count - 1; j++)
{
if(i != j)
{
IsDuplicate = currentList.SequenceEqual(bunchOLists[j]);
}
}
}
Console.WriteLine("all List<int> are unique: " + (! IsDuplicate).ToString());
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
modified 17-Jan-14 2:13am.
|
|
|
|
|
Message Closed
modified 17-Jan-14 4:52am.
|
|
|
|
|
Actually, it looks to me he is implementing the right algorithm.
Veni, vidi, vici.
|
|
|
|
|
I am a little confused what to put in Q/A and what to put in discussion. Can somebody explain what kind of query is to be put to Q/A and Discussion?
|
|
|
|
|
|
Years ago there was more of a difference than there is now, with the language Forums, like this one, often a place where broad general issues in programming with a given language were discussed at length, and QA more of a place for specific technical problems, and help-seeking.
But, in the last four years, imho, these categories have broken down in spite of requests, and specific proposals, from many people (including this insignificant person), to do something to maintain the original purpose of having two kinds of forums.
Given the state of CodeProject now, I'd say it hardly matters where you post.
Depending on which way the wind is blowing, however, and your "role" on CP, you may, or may not, get roasted if certain trigger-happy members are around.
Everything changes.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
thank you sir that answered my question.
|
|
|
|
|
An excellent summary Bill.
|
|
|
|
|
How to use SQL store procedure in LINQ in C#?
|
|
|
|
|
|
I'm developing a GUI(which needs to use Microsoft Office Obj Lib) using VS2013 C# on .Net Framework 3.5. I publish it and it runs fine on my PC (Windows 7, 64-bit OS) and get the .exe file and try running it on user PC(Windows XP, 32-bit OS).
The installation error keeps mentioning "The application requires ... assembly Microsoft.Vbe.Interop Version 15.0.0.0 to be installed in GAC first".
So I included Microsoft.Vbe.Interop in References (although I don't need it), build the program and publish it. The problem still persists.
Is there anyway I could publish an execution file which can be installed on the user PC straight away?
Thanks! I'm kinda lost and any help is much appreciated.
|
|
|
|
|
If your application has dependencies on other libraries, then you are going to have to create an installer, that will install all dependencies. I do not know of any other way of compiling dependencies into your exe file.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
|
IIRC we had a similar problem some years ago. We needed to tick a checkbox in the Office setup of the target machine to include Interop into the installation.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Could you please elaborate more on this?
|
|
|
|
|
emma.sun.sts wrote: So I included Microsoft.Vbe.Interop in References
And where exactly did you reference it from?
|
|
|
|
|
From
C:\Program Files (x86)\Microsoft Visual Studio 13.0\Visual Studio Tools for Office\PIA\Office14
|
|
|
|
|
Excellent.
You might have to play round with the options a bit since they move. But basically you need to find an option that will cause the dll to be copied into your build (when you look at the build directory the file will be there.)
Under VS 2008 you do this by (I think)
- Right clicking on reference
- Click on properties
- Set "Copy local" to true.
|
|
|
|
|
Hi Friend My name is makbul badi
and i Create one application to required video Conference(video chat )
application then how can i create using this application use in javascript or C#.net
thank you
modified 17-Feb-14 6:09am.
|
|
|
|
|
Member 10527273 wrote: so please help me With what? You have merely told us what you are trying to do, not what you need help with. If you are looking for sample code then go to the CodeProject Articles section[^].
Veni, vidi, abiit domum
|
|
|
|
|
i use OnItemCreated in repeater like :
<asp:Repeater runat="server" ID="DaysRepeater" DataSourceID="ObjDsDaysRepeater" OnItemCreated="DaysRepeater_ItemCreated">
<ItemTemplate>
<asp:repeater runat="server" id="PersonelsRepeater" datasourceid="ObjDsDevisionPersonel" onitemdatabound="PersonelsRepeater_ItemDataBound">
and
protected void DaysRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
}
protected void PersonelsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataModel model = new DataModel();
Label label = (Label)((Repeater)sender).Parent.FindControl("lblCurrentDate");
int num = Convert.ToInt32(label.Text);
if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
{
DataTable totalIssuancePersonelDataWithID = model.GetTotalIssuancePersonelDataWithID(this._wfItemId);
if (totalIssuancePersonelDataWithID != null)
{
}
but in debug none of the function didnt run
Does any body know what can i do?
|
|
|
|
|
As the problem is more ASP.net I would suggest that you put the question in that forum[^].
Also you said that none of the method ran, have you put a breakpoint on the first line of the method and stepped through it?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I'm working on a project in which I'm working with my serial ports. When I open my serial port after that I'll have to send 4 requests. SO for sending request my code is:
private string ByteArrayToHexString(byte[] data)
{
StringBuilder sb = new StringBuilder(data.Length * 3);
foreach (byte b in data)
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
return sb.ToString().ToUpper();
}
private void senddata1(String str)
{
byte[] data = HexStringToByteArray(str);
comport.Write(data, 0, data.Length);
}
This function will create a method to send data. On timer tick event I'm sending this Data:
private void timer1_Tick(object sender, EventArgs e)
{
senddata1(s1);
senddata1(s2);
senddata1(s3);
senddata1(s4);
}
Note:after every senddata1() function system will get a response.
So the problem is When I'm sending data I'm not getting the response because system is unable to read all senddata. I want to manage my program in a way so that I can send data after every 250 mili second. Like this:
SendData1(s1);
get response from the system
senddata1(s2);
get response from the system
get response is being handled in like this:
comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
So is there a way I can manage my program. Please share your opinions.
modified 16-Jan-14 4:46am.
|
|
|
|
|
Since you send all 4 strings directly after each other, you cannot receive the responses in between, of course. Send one string, receive the response, send next string, receive, etc. After having received the response for the last string, restart the timer.
|
|
|
|
|
Do you really mean 250 seconds ? My guess is: you mean milliseconds.
Why don't you set a boolean flag in the comport.DataReceived EventHandler, and use a 'while loop in your code after each send ? Here's a very rough sketch [1]:
using System.Diagnostics;
private bool hasResponded = false;
private Stopwatch theStopWatch;
private int waitHowLong1 = 250;
private int waitHowLong2 = 3000;
private void SerialDataReceivedEventHandler(dynamic port_DataReceived)
{
hasResponded = true;
}
private void senddata1(String str)
{
hasResponded = false;
theStopWatch = Stopwatch.StartNew();
while(true)
{
if (theStopWatch.ElapsedMilliseconds >= waitHowLong1) break;
}
Console.WriteLine("250 ms. wait done");
theStopWatch.Stop();
theStopWatch.Reset();
theStopWatch.Start();
while (true)
{
if (theStopWatch.ElapsedMilliseconds >= waitHowLong2) break;
}
theStopWatch.Stop();
Console.WriteLine("3000 ms. wait done");
if (! hasResponded) Console.WriteLine("failed to handle update");
} [1] Note: the above is untested code: it will compile as shown here (certain lines commented out, and missing parameter Type for SerialDataReceivedEventHandler "fudged"), but there's no guarantee beyond that; use this code as a source of ideas only.
[2] examples of using System.Diagnostic.Stopwatch: [^]
[3] Note: if you are working with .NET 4.5, and Windows 8, by all means use the new Task.Delay method with Wait argument in System.Threading.Tasks: [^].
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|