Code
try {
InputStream is = new FileInputStream(f);
in = new Scanner(is);
while (in.hasNextLine()) {
String tmp = in.nextLine();
listOne.add(tmp);
choices.put(i, tmp);
i++;
}
} catch (IOException ex) {
ex.printStackTrace();
}
for(String s: listOne) {
flag = true;
while (flag) {
i = rand.nextInt(10) + 1;
if (s != choices.get(i) && bitmap[i] == 0) {
listTwo.put(i, s);
bitmap[i] = 1;
flag = false;
} else {
continue;
}
}
}
So I wrote some spaghetti which I used to randomize signatures in a secret santa contest.
I am guessing there would have been an easier way to do it.
Basically, you have a list of n names (I hardcoded 10 because me a year from now can go fuck himself)
You must match each name with one of the other names in the list that isn't itself.
However, you cannot give the same sig to multiple people
for example
{a, b, c}
a --> b
b --> c
c --> a
but you cannot do like
a --> b
c --> b
b --> a
To solve the first problem, I just used Random()
for the 2nd problem, I had to use a bitmap (I had used one before for an OS assignment and it worked wonders!)
I feel like I declared too many variables/structures and that there is more than likely a better solution.
I hacked that shit out in like 20 mins (because I suck at java file I/O)
anyways MERRY XMAS and don't laugh too hard
This post was edited by Eep on Dec 26 2014 01:01am