|
Not true, this is a perfectly valid question for this forum.
|
|
|
|
|
My point is that in order to get more answers it might be better to post it in the quick answers section.
Just look at the number of responses during almost 24 hours.
|
|
|
|
|
That's hardly a reason to repost it.
|
|
|
|
|
|
Given a List of Integers:
List<int> positions = new List<int>{1,2,3,4,5};
How would I code a loop to get the following results for a given number of iterations {n}:
n P1 P2
1 1 5
2 2 1
3 3 2
4 4 3
5 5 4
6 1 5
7 2 1
8 3 2
9 4 3
10 5 4
...
This should be simple but I have brain freeze.
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
p1 almost looks like n mod 5 + (5 iif prev result is 0)
p2 almost looks like p1 - 1 + (5 iif prev result is 0)
'g'
|
|
|
|
|
List<int> positions = new List<int> { 1, 2, 3, 4, 5 };
for (int n = 1, p1 = 0, p2 = 4; n <= 10; ++n, ++p1, ++p2)
{
p1 %= positions.Count;
p2 %= positions.Count;
Console.WriteLine("{0,2} {1} {2}", n, positions[p1], positions[p2]);
}
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
That works well and creates the list for n iterations.
How about finding the value of p1 and p2 when n is a defined number?
int n = 23;
p1 = ?
p2 = ?
...
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
If n starts with 1, then
p1 = (n-1) % positions.Count;
p2 = (positions.Count + n - 2) % positions.Count;
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Here what I ended up using:
public List<int> GetPositions(int n, int posCount)
{
int pos1 = n % posCount;
int pos2 = pos1 == 0 ? posCount - 1 : pos1 - 1;
return new List<int>{pos1, pos2};
}
...
int n = 0;
List<int> positions = new List<int>{0,1,2,3,4};
while( n < 10)
{
List<int> res = GetPositions(n, positions.Count)
Console.WriteLine("Count{0}: Pos1 {1} - Pos2 {2}", n, res[0], res[1]);
n++;
}
Thanks to you and G for your help clearing the fog!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
You are welcome.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
+5 for this wonderful code "haiku"
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
Thank you.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
I hope this doesn't sound picky-picky, but I kept studying the line of code that writes to the Console:
Console.WriteLine("{0,2} {1} {2}", n, positions[p1], positions[p2]);
Thinking that {0,2} did some exotic thing I had never seen before, but it appears it actually does nothing, and changing it to {0} produces no change in the output. Or, am I missing something ?
Once again, thanks for the great code example: you've expanded my understanding of what a C# 'for loop can do !
thanks, Bill
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
It's putting the space before the single digit numbers. Try changing it {0,4} to see the effect in greater detail.
|
|
|
|
|
Exactly.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Thanks Pete !
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
The MSDN documentation is reasonably clear (for once!):
A format item has this syntax:
{index[,alignment][:formatString]}
...
alignment
Optional. A signed integer that indicates the total length of the field into which the argument is inserted and whether it is right-aligned (a positive integer) or left-aligned (a negative integer). If you omit alignment, the string representation of the corresponding argument is inserted in a field with no leading or trailing spaces.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: he MSDN documentation is reasonably clear (for once!):
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Thanks, Richard !
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
I need RC4 code in c# please email me the code at "hassan.redrose.muhammad@gmail.com" please
modified 6-Sep-14 14:38pm.
|
|
|
|
|
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
You looking for sympathy?
You'll find it in the dictionary, between sympathomimetic and sympatric
(Page 1788, if it helps)
|
|
|
|
|
|
By publishing your email address in a public forum, you ought not expect to receive code to be sent to you, but spam or malware! Do you understand why? There are many bots in the web harvesting addresses just for the purposes of spammers and hackers.
|
|
|
|
|