Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add capabilities to form a team with different levels

  • Loading branch information...
commit d3a137e63829e09101b5873d9d5298e04e74b031 1 parent 547c2db
@ksetyadi authored
Showing with 96 additions and 5 deletions.
  1. +45 −1 README.md
  2. +51 −4 src/com/ksetyadi/randompair/RandomPair.java
View
46 README.md
@@ -18,4 +18,48 @@ Compile it:
and then run:
- java com.ksetyadi.randompair.RandomPair < people_list.txt
+ java com.ksetyadi.randompair.RandomPair < people_list.txt
+
+Example
+-------
+
+EXAMPLE 1
+
+Everyone has the same level so you want to randomly form them directly into the team.
+
+Example Input:
+Satya
+Armanto
+Ksetyadi
+Robby
+Yanbul
+Ary
+Levady
+Wandre
+
+Example Output:
+Team #1: Robby - Satya
+Team #2: Ksetyadi - Wandre
+Team #3: Ary - Levady
+Team #4: Yanbul - Armanto
+
+
+EXAMPLE 2
+
+Some people have different level. You want to team up those people so there is no team with both member have the same level.
+
+Example Input:
+#Satya
+Armanto
+Ksetyadi
+#Robby
+#Yanbul
+Ary
+#Levady
+Wandre
+
+Example Output:
+Team #1: Levady - Wandre
+Team #2: Robby - Ksetyadi
+Team #3: Armanto - Satya
+Team #4: Ary - Yanbul
View
55 src/com/ksetyadi/randompair/RandomPair.java
@@ -10,8 +10,11 @@
public class RandomPair {
private static List<String> originalList;
+ private static List<String> playoffList;
private static Map<String, String> resultPair;
+ private static boolean playoffMode = false;
+
public static void main(String[] args) {
originalList = new ArrayList<String>();
@@ -20,15 +23,42 @@ public static void main(String[] args) {
while(s.hasNextLine()) {
String line = s.nextLine();
+
+ if (line.charAt(0) == '#') {
+
+ if (!playoffMode) {
+ playoffList = new ArrayList<String>();
+ playoffMode = true;
+ }
+
+ playoffList.add(line.substring(1, line.length()));
+ continue;
+ }
+
originalList.add(line);
}
- if (originalList.size() % 2 != 0) {
- System.out.println("The number of entity should be even.");
- return;
+ if (playoffMode) {
+ if (playoffList.size() != originalList.size()) {
+ System.out.println("The list between playoff (" +
+ playoffList.size() + ") and non-playoff (" +
+ originalList.size() + ") is different. ");
+
+ return;
+ }
+ } else {
+ if (originalList.size() % 2 != 0) {
+ System.out.println("The number of entity should be even.");
+ return;
+ }
+ }
+
+ if (playoffMode) {
+ resultPair = generateResultPair(playoffList, originalList);
+ } else {
+ resultPair = generateResultPair(originalList);
}
- resultPair = generateResultPair(originalList);
Set<String> keySet = resultPair.keySet();
int i = 1;
@@ -53,4 +83,21 @@ public static void main(String[] args) {
return result;
}
+
+ private static Map<String, String> generateResultPair(List<String> playoffList,
+ List<String> originalList) {
+
+ Collections.shuffle(playoffList);
+ Collections.shuffle(originalList);
+
+ int size = playoffList.size();
+
+ Map<String, String> result = new HashMap<String, String>();
+
+ for (int i = 0; i < size; i++) {
+ result.put(playoffList.get(i), originalList.get(i));
+ }
+
+ return result;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.