|
Maybe there is no better way?
|
|
|
|
|
I don't give up that easily... Have to think on this a while.
|
|
|
|
|
Thanks!
After a few modification that implementations works for me. What I needed was a lexicographical order permutation generator. Now I have to implement it myself to learn how to answer over-inquisitive teacher's questions.
Thanks again --
Greetings - Jacek
|
|
|
|
|
Here are my modifications[^] which
1. Use C# 2.0 goodies
2. All operations are in situ now.
Greetings - Jacek
|
|
|
|
|
harold aptroot wrote: edit: then you could skip x iterations by just adding x to the "permutation number"
In terms of the factoriadic numbers, I was interested in skipping n! iterations, which means adding 1 to n-th digit of a factoriadic.
Greetings - Jacek
|
|
|
|
|
OK, I have given up my algoritm and have been using an implementation posted by harold (thanks mate). I have added two methods:
public void First(int[] beginning, int order)
{
var check = new bool[order];
for (int i = 0; i < beginning.Length; i++)
{
check[beginning[i]] = true;
data[i] = beginning[i];
}
int checkI = 0;
for (int i = beginning.Length; i < order; i++)
{
while (check[checkI])
checkI++;
data[i] = checkI;
checkI++;
}
}
and
public static IEnumerable<Permutation> GetPermutations(int order)
{
var permutation = new Permutation(order);
while ((permutation = permutation.GetSuccessor()) != null)
yield return permutation;
}
And the usage:
var perm = new Permutation(5);
var beginning = new[] { 1 };
foreach (Permutation permutation in Permutation.GetPermutations(5))
{
if (permutation.StartsWith(beginning))
{
permutation.First(new [] { 2}, perm.Order);
}
Console.WriteLine("{0} {1} {2} {3} {4}", permutation[0], permutation[1], permutation[2], permutation[3], permutation[4]);
}
The code above skips all permutations in form [1....].
Thanks!
Greetings - Jacek
|
|
|
|
|
Good I'm glad it solved your problem
Sorry for the lack of replies btw, I was sleeping lol
|
|
|
|
|
Where is the best place to write application files on Vista or W7? I'm looking for a global (accessible by all users) location to create a directory structure so I can write log files, settings, and user created files into separate directories.
My original idea was to use subdirectories under my root program directory but Program Files is locked by default and I don't want to disable the UAC. I've heard issues with the virtualization that some programs will see the virtual directory and some won't.
I thought about using the Users\Public folder, but I wasn't sure if this is the right place.
Is is better/possible to elevate my permissions so I can write to the Program Files directory?
Thanks for any help pointing me in the right direction.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
I usually store things on a per-user basis, but I think Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) is supposed to give you exactly that, regardless of which OS you're on.
|
|
|
|
|
Thanks for your help... and making me feel very ignorant.
I was looking at the list that had all of the special folders and saw CommonProgramFiles, COmmonDocuments, CommonPrograms, etc. After seeing your response, I looked at the list again and I bet you'll never guess what the second one was.
I was looking for something referencing public.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
Heh, don't feel bad... There's a ridiculous amount of content in the framework... I've done the same thing in other parts.
|
|
|
|
|
Hi there,
I know how to control the master volume of a system, but how I should do it individually for each speaker? - I didn't found any hint so far.
E.G.: A 5.1 or 7.1 System has 6/8 speakers and I want to reduce the volume of center and sub but increase the back speakers for example.
I'm creating an media player where I want to control the individual volume of those speakers.
I appreciate your help!
Zsolt / Germany
|
|
|
|
|
I want to automated call function "save as" and choise "save as type = webpage completed..." from Webbrowser Control (Windows Forms, C#).
I found the source code in link "http://www.codeproject.com/KB/shell/iesaveas.aspx?msg=1101501" but i can't understand C++. From this code i want to build a funtion DownloadHTMLCompleted(String URI, String FileName) by C++ or C#, then call this funtion from C#.
Help me!
|
|
|
|
|
Nguyễn Đức Thiện wrote: but i can't understand C++.
Nguyễn Đức Thiện wrote: build a funtion ... by C++
You say you don't understand C++ but want to create a function in C++
only two letters away from being an asset
|
|
|
|
|
yes!
I can't understand C++ but i can call this from C# (because i think may be anyone help me by C++, this way is faster)
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:31am.
|
|
|
|
|
Hi!
If I use File.WriteAllText(file_name, text_html) I can't save completed webpage (include: image, css, js,..)
|
|
|
|
|
Hi everyone, as already stated I am completely new to c#, I am trying to write a program that will generate random scores for football games in a league where each team plays one another once, however after generating the score i wish to assess which team should be awarded 3 points for winning or if both should be awarded 1 point, so I can produce these in a league table. I have written this code but get an error saying " input string was not in a correct format", here is the part of my code causing the error:
if (Convert.ToInt16(score.Text) > Convert.ToInt16(score2.Text))
{
points12 += 3;
}
else if (Convert.ToInt16(score.Text) < Convert.ToInt16(score2.Text))
{
points4 += 3;
}
else
{
points4 += 1;
points12 += 1;
}
Any help would be greatly appreciated
Thanks in advance
|
|
|
|
|
It would only make sense for you to get that error on the first line of code that you have posted but it would still have been nice if you had indicated the line.
The error means that either score or score2 contains something that cannot be converted into an int16 . Have you maybe entered an 'o' (letter O) rather than a 0 (number zero) or 'L' instead of 1?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
My apologies, the error does indeed occur on the first lie of code posted.
I've check through my code however and there doesn't seem to be an instance where I've used a letter 'o'instead of number zero or letter 'l' instead of number one.
Thankyou though
|
|
|
|
|
It wouldn't be in your code, it would be what is entered into the TextBoxes (score and score2 ) but never mind.
In order to tie down where the error is you could make your code a little more long winded, temporarily, something like this:
Int16 score = Convert.ToInt16(score.Text);
Int16 score2 = Convert.ToInt16(score2.Text);
if (score > score2)
{
points12 += 3;
}
else if (score < score2)
{
points4 += 3;
}
else
{
points4 += 1;
points12 += 1;
}
That way you will get an error on the line for the incorrect text and can narrow down your search for a solution.
BTW: Do you notice how my code sample is nicely formatted? it is because I have surrounded it with <pre>code goes here</pre> tags. That doesn't format it for you but will preserve any formatting you put in. You can do it automatically by highlighting your code and clicking on the 'code block' widget, just above the reply text box.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Well you shouldn't be saving the data in text for, you should be saving it internally as a int, use this format:
class Game
{
public int GameScore;
public int LeageScore;
public Game(int S, int LS)
{
GameScore = S;
LeagueScore = LS;
}
}
class Team{
public List<Game> Games = new List<Game>()
public string Name;
public Team(string _Name)
{
Name = _Name;
}
public int CumulativeLeagueScore
{
get
{
int ret = 0;
foreach(Game G in this.Games){ret+=G.LeagueScore;}
return ret;
}
}
public void AddGame(int score, int leagescore)
{
this.Games.Add(new Game(score, leagescore);
}
}
that way when you want to add in things like statistics, and multiple years of records it will be easier.
But your issue is coming from using text somewhere in between your RNG(Random number generator) (probably Math>Random()..?) and your test.. Unless you are using dice and then typing it into a form... in which case only convert to int once and then whenever you want to display the info use ToString().
|
|
|
|
|
This did nothing at all to answer the question.
only two letters away from being an asset
|
|
|
|
|
Sorry I am too accustomed to talking to myself...
If You are Actually generating the numbers randomly then you shouldn't need text boxes.
If you use the class structure from before then your code will condense greatly and become easier to debug.
this would circumvent the need to use a text box anywhere in the application(assuming that you are not using an outside source to "randomly" generate the data). and Once that has been accomplished the "bug" would not be there.. (because there wouldn't be any string to int conversions).
I guess I am so against the notion of string-> Int that I see it and it makes me revert to a cave man.
|
|
|
|
|
Again, both of your responses have absolutely nothing to do with the original problem and this one is just plain ridiculous.
Darren Shields wrote: get an error saying " input string was not in a correct format"
Nothing at all in your response even remotely tried to help with this.
ely_bob wrote: this would circumvent the need to use a text box anywhere in the application
And how do you get data from the user, telepathy?
Quit while you're behind and go back to the cave.
only two letters away from being an asset
|
|
|
|