Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CodebreakersTrial5 {
- // Concept:
- // Letters are taken one by one from the first word to the last (TODO: permutations of words)
- // Letter n of word m is inserted into scheme as follows:
- // Operations are modulo(divider)
- // Every time the modulo reaches divider, we restart at [n + 1][0] and continue
- private String[] input = { "aspirin", "bread", "butter", "cheese", "edgingshears", "pears", "potatoes", "straws", "toffee" };
- private ArrayList<String> bucket;
- public void solve(String[] input, int divider) {
- int size = input.size;
- bucket = new ArrayList<String>(size);
- // Init strings (avoids null pointer exception)
- for(int i = 0; i < size; i++)
- bucket.set(i, "");
- // Merge input strings
- String overall = merge(input);
- int totalLetters = overall.length();
- // Pick letter and modify string
- int mod = 0; // Keeps track of row
- int bucketPos = 0; // Keeps track of column
- for(int i = 0; i < totalLetters; i++) {
- char c = overall.charAt(i);
- if(mod < divider) {
- // Put in [n][m + 1]
- String extract = bucket.get(bucketPos).concat(c);
- bucket.set(bucketPos, extract);
- mod++;
- }
- else {
- // Put in [n + 1][0]
- mod = 0;
- bucketPos++;
- String extract = bucket.get(bucketPos).concat(c);
- bucket.set(bucketPos, extract);
- }
- }
- }
- // Permutes the strings
- private void permute(String[] input) {
- }
- // Concat all input strings
- private String merge(String[] input) {
- String out = "";
- int size = input.size;
- for(int i = 0; i < size; i++)
- out.concat(input[i]);
- return out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement