Skip to main content
Added singleUltraFizzBuzz implementation
Source Link
Solomon Ucko
  • 1.6k
  • 1
  • 10
  • 17

I would probably create the following methods (I have left singleUltraFizzBuzz undefined so I don't end up writing the whole thing; singleUltraFizzBuzz should do the check for the empty string):

public static abstract String singleUltraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integerint i) {
    StringBuilder result = new StringBuilder();
    bool isEmpty = true;
    
    for(Map.Entry<String, Object> entry : fizzBuzzes.entrySet()) {
        if(i % entry.getKey() == 0) {
            result.append(entry.getValue());
            isEmpty = false;
        }
    }
    
    return isEmpty ? i.toString() : result.toString();
}

public static String ultraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integerint maxImin, int max) {
    String out = "";
    
    for(int i = 1;min; i < 100;max; i++) {
        out = out + singleUltraFizzBuzz(fizzBuzzes, i) + "\n";
    }
}

which would be called as follows:

SortedMap<Integer, String> fizzBuzzes = new TreeMap<>();
fizzBuzzes.put(3, "fizz");
fizzBuzzes.put(5, "buzz");
System.out.write(ultraFizzBuzz(fizzBuzzes, 1, 100));

I would probably create the following methods (I have left singleUltraFizzBuzz undefined so I don't end up writing the whole thing; singleUltraFizzBuzz should do the check for the empty string):

public static abstract String singleUltraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integer i);

public static String ultraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integer maxI) {
    String out = "";
    
    for(int i = 1; i < 100; i++) {
        out = out + singleUltraFizzBuzz(fizzBuzzes, i) + "\n";
    }
}

which would be called as follows:

SortedMap<Integer, String> fizzBuzzes = new TreeMap<>();
fizzBuzzes.put(3, "fizz");
fizzBuzzes.put(5, "buzz");
System.out.write(ultraFizzBuzz(fizzBuzzes, 100));

I would probably create the following methods:

public static String singleUltraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, int i) {
    StringBuilder result = new StringBuilder();
    bool isEmpty = true;
    
    for(Map.Entry<String, Object> entry : fizzBuzzes.entrySet()) {
        if(i % entry.getKey() == 0) {
            result.append(entry.getValue());
            isEmpty = false;
        }
    }
    
    return isEmpty ? i.toString() : result.toString();
}

public static String ultraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, int min, int max) {
    String out = "";
    
    for(int i = min; i < max; i++) {
        out = out + singleUltraFizzBuzz(fizzBuzzes, i) + "\n";
    }
}

which would be called as follows:

SortedMap<Integer, String> fizzBuzzes = new TreeMap<>();
fizzBuzzes.put(3, "fizz");
fizzBuzzes.put(5, "buzz");
System.out.write(ultraFizzBuzz(fizzBuzzes, 1, 100));
Source Link
Solomon Ucko
  • 1.6k
  • 1
  • 10
  • 17

I would probably create the following methods (I have left singleUltraFizzBuzz undefined so I don't end up writing the whole thing; singleUltraFizzBuzz should do the check for the empty string):

public static abstract String singleUltraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integer i);

public static String ultraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integer maxI) {
    String out = "";
    
    for(int i = 1; i < 100; i++) {
        out = out + singleUltraFizzBuzz(fizzBuzzes, i) + "\n";
    }
}

which would be called as follows:

SortedMap<Integer, String> fizzBuzzes = new TreeMap<>();
fizzBuzzes.put(3, "fizz");
fizzBuzzes.put(5, "buzz");
System.out.write(ultraFizzBuzz(fizzBuzzes, 100));