Little Problem  
Author Message
fsd





PostPosted: 2003-12-24 0:06:00 Top

java-programmer, Little Problem I have three numbers - 1, 2 & 3.

A randomly selected one of the three are stored in 'var1', and another
randomly selected one is in 'var2'.

How do I find out the number that is left over?

I tried a while loop but I couldn't get it to work...

TIA


 
Joseph Dionne





PostPosted: 2003-12-24 0:14:00 Top

java-programmer >> Little Problem fsd wrote:
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>
> I tried a while loop but I couldn't get it to work...
>
> TIA
>
>

Add var1 and var2 together

psuedo code;

switch(var1 + var2)
case 3: three is left
case 4: two is left
case 5: one is left

 
Nicholas Paldino [.NET/C# MVP]





PostPosted: 2003-12-24 0:15:00 Top

java-programmer >> Little Problem fsd,

What I would do is store the values in an ArrayList. When you pick the
numbers randomly, remove them from the ArrayList and place into a new
collection. This would require you to change the range of selected random
numbers every time (the first time you pick a random number from the range
1-3, then 1-2, etc, etc). You just have to stop when you have enough
numbers selected. Then, whatever is left over in the ArrayList is what was
not selected.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- email***@***.com

"fsd" <email***@***.com> wrote in message
news:bs9p1f$b81nj$email***@***.com...
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>
> I tried a while loop but I couldn't get it to work...
>
> TIA
>
>


 
 
Sudsy





PostPosted: 2003-12-24 0:20:00 Top

java-programmer >> Little Problem fsd wrote:
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>
> I tried a while loop but I couldn't get it to work...
>
> TIA

Think! What do the numbers 1, 2 and 3 add up to? Add up the two
you know, subtract from 6 and you've got the third.
Seems obvious now, eh?

 
 
Dmitriy Lapshin [C# / .NET MVP]





PostPosted: 2003-12-24 0:21:00 Top

java-programmer >> Little Problem Something like this (pseudo-code):

var1 = Random(3);
var2 = Random(3);
while (var2 == var1)
{
var2 = Random(3);
}

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"fsd" <email***@***.com> wrote in message
news:bs9p1f$b81nj$email***@***.com...
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>
> I tried a while loop but I couldn't get it to work...
>
> TIA
>
>

 
 
Eric Sosman





PostPosted: 2003-12-24 0:22:00 Top

java-programmer >> Little Problem fsd wrote:
>
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?

if (var1 != var2)
System.out.println ( (6 - var1 - var2) + " is missing" );
else
System.out.println ("Two values are missing, you liar!");

--
email***@***.com
 
 
Marco Martin





PostPosted: 2003-12-24 0:24:00 Top

java-programmer >> Little Problem try this;

int nArrayPos = -1;
for(int x = 0; x < arrayOfVars.Length; x++)
{
if(var1 != arrayOfVars[x] & var2 != arrayOfVars[x])
{
nArrayPos = x;
}
}
if(nArrayPos != 01)
MessageBox.Show(arrayOfVars[x].ToString() + " is not beeing used");


"fsd" <email***@***.com> wrote in message
news:bs9p1f$b81nj$email***@***.com...
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>
> I tried a while loop but I couldn't get it to work...
>
> TIA
>
>


 
 
fsd





PostPosted: 2003-12-24 0:32:00 Top

java-programmer >> Little Problem "Sudsy" <email***@***.com> wrote in message
news:email***@***.com...
> fsd wrote:
> > I have three numbers - 1, 2 & 3.
> >
> > A randomly selected one of the three are stored in 'var1', and another
> > randomly selected one is in 'var2'.
> >
> > How do I find out the number that is left over?
> >
> > I tried a while loop but I couldn't get it to work...
> >
> > TIA
>
> Think! What do the numbers 1, 2 and 3 add up to? Add up the two
> you know, subtract from 6 and you've got the third.

Simple, but highly effective. Well done.

> Seems obvious now, eh?

It does *now*. :)


 
 
Marco Martin





PostPosted: 2003-12-24 0:51:00 Top

java-programmer >> Little Problem Sorry, the last if should have been;

if(nArrayPos != -1)

"Marco Martin" <email***@***.com> wrote in message
news:9YZFb.6630$d%email***@***.com...
> try this;
>
> int nArrayPos = -1;
> for(int x = 0; x < arrayOfVars.Length; x++)
> {
> if(var1 != arrayOfVars[x] & var2 != arrayOfVars[x])
> {
> nArrayPos = x;
> }
> }
> if(nArrayPos != 01)
> MessageBox.Show(arrayOfVars[x].ToString() + " is not beeing used");
>
>
> "fsd" <email***@***.com> wrote in message
> news:bs9p1f$b81nj$email***@***.com...
> > I have three numbers - 1, 2 & 3.
> >
> > A randomly selected one of the three are stored in 'var1', and another
> > randomly selected one is in 'var2'.
> >
> > How do I find out the number that is left over?
> >
> > I tried a while loop but I couldn't get it to work...
> >
> > TIA
> >
> >
>
>


 
 
Brad BARCLAY





PostPosted: 2003-12-24 1:38:00 Top

java-programmer >> Little Problem fsd wrote:
> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?

Think more mathematically. Sum the numbers you have together, and
deduct them from the sum of all three numbers. No loops required.

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org

 
 
Eric Johannsen





PostPosted: 2003-12-24 1:43:00 Top

java-programmer >> Little Problem Unless I'm missing something, this would not work because theoretically you
could get "1" as your answer every time...and that would be stored in each
element of the array list.

Eric

"Nicholas Paldino [.NET/C# MVP]" <email***@***.com> wrote in
message news:#r#email***@***.com...
> fsd,
>
> What I would do is store the values in an ArrayList. When you pick
the
> numbers randomly, remove them from the ArrayList and place into a new
> collection. This would require you to change the range of selected random
> numbers every time (the first time you pick a random number from the range
> 1-3, then 1-2, etc, etc). You just have to stop when you have enough
> numbers selected. Then, whatever is left over in the ArrayList is what
was
> not selected.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - email***@***.com
>
> "fsd" <email***@***.com> wrote in message
> news:bs9p1f$b81nj$email***@***.com...
> > I have three numbers - 1, 2 & 3.
> >
> > A randomly selected one of the three are stored in 'var1', and another
> > randomly selected one is in 'var2'.
> >
> > How do I find out the number that is left over?
> >
> > I tried a while loop but I couldn't get it to work...
> >
> > TIA
> >
> >
>
>

 
 
Nicholas Paldino [.NET/C# MVP]





PostPosted: 2003-12-24 1:59:00 Top

java-programmer >> Little Problem Eric,

That's not what I meant. The array list would be populated with values,
but not randomly. It would be populated with the set of values to select
from (however one comes to those values is irrelevant). Then, a random
number between 0 and the length of the array - 1 is chosen, representing the
index that the value selected is at. That value is placed in another
collection, and the element at that index is removed from the original set.
This reduces the length by one. Even if one is selected every time, it
works because the elements are shifted down one with each removal, providing
a different value.


--
- Nicholas Paldino [.NET/C# MVP]
- email***@***.com


"Eric Johannsen" <email***@***.com> wrote in message
news:h8%Fb.1938$email***@***.com...
> Unless I'm missing something, this would not work because theoretically
you
> could get "1" as your answer every time...and that would be stored in each
> element of the array list.
>
> Eric
>
> "Nicholas Paldino [.NET/C# MVP]" <email***@***.com> wrote
in
> message news:#r#email***@***.com...
> > fsd,
> >
> > What I would do is store the values in an ArrayList. When you pick
> the
> > numbers randomly, remove them from the ArrayList and place into a new
> > collection. This would require you to change the range of selected
random
> > numbers every time (the first time you pick a random number from the
range
> > 1-3, then 1-2, etc, etc). You just have to stop when you have enough
> > numbers selected. Then, whatever is left over in the ArrayList is what
> was
> > not selected.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - email***@***.com
> >
> > "fsd" <email***@***.com> wrote in message
> > news:bs9p1f$b81nj$email***@***.com...
> > > I have three numbers - 1, 2 & 3.
> > >
> > > A randomly selected one of the three are stored in 'var1', and another
> > > randomly selected one is in 'var2'.
> > >
> > > How do I find out the number that is left over?
> > >
> > > I tried a while loop but I couldn't get it to work...
> > >
> > > TIA
> > >
> > >
> >
> >
>


 
 
Alex Hunsley





PostPosted: 2003-12-24 21:13:00 Top

java-programmer >> Little Problem fsd wrote:

>I have three numbers - 1, 2 & 3.
>
>A randomly selected one of the three are stored in 'var1', and another
>randomly selected one is in 'var2'.
>
>How do I find out the number that is left over?
>
>I tried a while loop but I couldn't get it to work...
>
>TIA
>
You could perhaps use the observation that the final number is equal to:

6 - var1 - var2

alex

 
 
Walter Mitty





PostPosted: 2003-12-28 23:13:00 Top

java-programmer >> Little Problem "fsd" <email***@***.com> brightened my day with his incisive wit when in
news:bs9p1f$b81nj$email***@***.com he conjectured that:

> I have three numbers - 1, 2 & 3.
>
> A randomly selected one of the three are stored in 'var1', and another
> randomly selected one is in 'var2'.
>
> How do I find out the number that is left over?
>

Subtract the two you have from 6.
 
 
Zdenek





PostPosted: 2006-4-30 23:41:00 Top

java-programmer >> Little Problem Hello
I have a problem with mysql query
I have a table Teams and field 'date' (12-01-2006 format)

I want to see all records but date format I want is 12/01 %d/%m

My query

SELECT Date, p.Category, t1.Teams, t2.Teams, Prediction, Stake, Odds,
Win_Lose, Profit, Score, ZakladyID
FROM
Teams as t1, Teams as t2, Zaklady as m, Category as p
WHERE
Win_Lose = '' AND
p.CategoryID = m.Category AND
t1.TeamsID = m.Team1 AND
t2.TeamsID = m.Team2


How can I make it
Please help me in making right query

Best Regards
Pat



 
 
J.O. Aho





PostPosted: 2006-5-1 1:21:00 Top

java-programmer >> Little Problem Zdenek wrote:
> Hello
> I have a problem with mysql query
> I have a table Teams and field 'date' (12-01-2006 format)
>
> I want to see all records but date format I want is 12/01 %d/%m

SELECT CONCAT(SUBSTR(Date,0,2),'/',SUBSTR(Date,3,2)), p.Category, t1.Teams,
t2.Teams, Prediction, Stake, Odds, Win_Lose, Profit, Score, ZakladyID FROM
Teams as t1, Teams as t2, Zaklady as m, Category as p WHERE Win_Lose = '' AND
p.CategoryID = m.Category AND t1.TeamsID = m.Team1 AND t2.TeamsID = m.Team2

Should work, but sure there are better ways to do it.



//Aho