Advertisement
heavenriver

CodebreakersTrial5.java (Stub)

Jul 17th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CodebreakersTrial5 {
  4.    
  5. // Concept:
  6. // Letters are taken one by one from the first word to the last (TODO: permutations of words)
  7. // Letter n of word m is inserted into scheme as follows:
  8. // Operations are modulo(divider)
  9. // Every time the modulo reaches divider, we restart at [n + 1][0] and continue
  10.  
  11. private String[] input = { "aspirin", "bread", "butter", "cheese", "edgingshears", "pears", "potatoes", "straws", "toffee" };
  12. private ArrayList<String> bucket;
  13.  
  14. public void solve(String[] input, int divider) {
  15.     int size = input.size;
  16.     bucket = new ArrayList<String>(size);
  17.    
  18.     // Init strings (avoids null pointer exception)
  19.     for(int i = 0; i < size; i++)
  20.         bucket.set(i, "");
  21.    
  22.     // Merge input strings
  23.     String overall = merge(input);
  24.     int totalLetters = overall.length();
  25.    
  26.     // Pick letter and modify string
  27.     int mod = 0; // Keeps track of row
  28.     int bucketPos = 0; // Keeps track of column
  29.     for(int i = 0; i < totalLetters; i++) {
  30.         char c = overall.charAt(i);
  31.         if(mod < divider) {
  32.             // Put in [n][m + 1]
  33.             String extract = bucket.get(bucketPos).concat(c);
  34.             bucket.set(bucketPos, extract);
  35.             mod++;
  36.             }
  37.         else {
  38.             // Put in [n + 1][0]
  39.             mod = 0;
  40.             bucketPos++;
  41.             String extract = bucket.get(bucketPos).concat(c);
  42.             bucket.set(bucketPos, extract);
  43.             }
  44.         }
  45.     }
  46.  
  47. // Permutes the strings
  48. private void permute(String[] input) {
  49.    
  50.     }
  51.    
  52. // Concat all input strings
  53. private String merge(String[] input) {
  54.     String out = "";
  55.     int size = input.size;
  56.     for(int i = 0; i < size; i++)
  57.         out.concat(input[i]);
  58.     return out;
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement