HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Integers that can't be the same

11-04-2007, 01:36 AM#1
SkriK
I have this.

Trigger:
For each (Integer A) 1 to 8 do actions
Collapse Loop - Actions
Set TempInt[(Integer A)] = Random number between 1 and 20

So i want if any of TempInt 1 through 8 is the same, i want the identical one to set -1. Possible without 10000000 If's?
11-04-2007, 02:16 AM#2
Vexorian
Sorry, I don't know GUI, pseudo code:

Code:
For each (integer A) 1 to 20 do
     set TempInt[(integer A) = (integer A)

For each (integer A) 1 to 8 do
     set pos = Random number between 1 and 20
     set x    = TempInt[pos]
     set TempInt[pos] = TempInt[(integer A)]
     set TempInt[(integer A)] = x
11-04-2007, 02:28 AM#3
MaD[Lion]
just run another loop to check them
or store the number used in array index to check if they are used
11-04-2007, 04:24 AM#4
zen87
something like this? i guess...
Collapse JASS:
if TempInt[1]==TempInt[2] and TempInt[2]==TempInt[3]... and TempInt[7]==TempInt[8] then
    //your code here
endif
11-04-2007, 05:38 AM#5
Strilanc
Trigger:
For each (Integer A) from 1 to 8 do actions
Collapse Loop - Actions
Collapse For each (Integer B) from ((Integer A) + 1) to 8 do actions
Collapse Loop - Actions
Collapse if TempInt[(Integer B)] == TempInt[(Integer A)] then
set TempInt[(Integer B)] = -1
11-04-2007, 07:44 AM#6
DioD
You must make integer pool and use numbers from this pool.
Also you can use unitgroup with units 1-2-3-4-5 or item\unit pool
11-04-2007, 11:58 AM#7
Vexorian
Go ahead and ignore my simple algorithm with linear complexity...
11-04-2007, 12:52 PM#8
cohadar
Collapse JASS:
For each (integer A) 1 to 20 do
     set TempInt[(integer A) = (integer A)

For each (integer A) 1 to 20 do
     set pos = Random number between 1 and 20
     set x    = TempInt[pos]
     set TempInt[pos] = TempInt[1]
     set TempInt[1] = x
11-04-2007, 03:49 PM#9
MaD[Lion]
vex's algorithm is best, also the one i was trying to say
11-04-2007, 03:55 PM#10
SkriK
Tried this without success:
Quote:
Originally Posted by Vexorian
Code:
For each (integer A) 1 to 20 do
     set TempInt[(integer A) = (integer A)

For each (integer A) 1 to 8 do
     set pos = Random number between 1 and 20
     set x    = TempInt[pos]
     set TempInt[pos] = TempInt[(integer A)]
     set TempInt[(integer A)] = x
Tried this without success:
Quote:
Originally Posted by zen87
something like this? i guess...
Collapse JASS:
if TempInt[1]==TempInt[2] and TempInt[2]==TempInt[3]... and TempInt[7]==TempInt[8] then
    //your code here
endif
Tried this without success:
Quote:
Originally Posted by Strilanc
Trigger:
For each (Integer A) from 1 to 8 do actions
Collapse Loop - Actions
Collapse For each (Integer B) from ((Integer A) + 1) to 8 do actions
Collapse Loop - Actions
Collapse if TempInt[(Integer B)] == TempInt[(Integer A)] then
set TempInt[(Integer B)] = -1
Tried this, and it worked:
Quote:
Originally Posted by cohadar
Collapse JASS:
For each (integer A) 1 to 20 do
     set TempInt[(integer A) = (integer A)

For each (integer A) 1 to 20 do
     set pos = Random number between 1 and 20
     set x    = TempInt[pos]
     set TempInt[pos] = TempInt[1]
     set TempInt[1] = x
Thanks cohadar. And thanks everyone who wanted to give a helping hand. ^^
11-04-2007, 04:21 PM#11
cohadar
Well we all know Vex does not know shit about programming :P

haha, kidding, his algorithm is more optimized and it works,
(assuming that you know how to implement it.)
You proabably nested for A loops...

Noob-friendly programming wins, yay.
11-04-2007, 05:09 PM#12
Salbrismind
I followed this thread and I was skeptical of Vexs code. I just went through step by step writing down all values on paper and it work quite well, amazing.
11-04-2007, 06:28 PM#13
PipeDream
You can find an implementation of the only correct way to shuffle (what vex wrote) in DARY.
11-04-2007, 07:31 PM#14
cohadar
Quote:
Originally Posted by PipeDream
You can find an implementation of the only correct way to shuffle (what vex wrote) in DARY.

"only correct way"
I mean really....
11-04-2007, 10:09 PM#15
MaD[Lion]
damn tat simple thing vex wrote is so fucking complex... someone tell me in words wat it does pls...