## Primary factors kata solution in Clojure

I am new to Clojure but I already know the functions and the lists, so I decided to implement the Prime Factors Kata solution. For any natural number, the function must return a list of all its prime factors, p. by 15 he should return (3 5).

It turned out that to implement a secure stack function you needed to use `loop` and `recur`, with which he was not familiar.

So does my solution seem idiomatic Clojure? What could be improved? Thank you!

``````(defn primeFactorsOf
"Return all prime factors of a number"
(n)
(loop (number n candidate 2 factors ())
(if (= number 1)
(reverse factors)
(if (= (mod number candidate) 0)
(recur (/ number candidate) candidate (conj factors candidate))
(recur number (inc candidate) factors)))))
``````

## Java Kata – String Calculator

I started learning Java recently. I am currently trying to improve my spaghetti code by solving different programming puzzles.

It would be amazing if someone could give me their opinion on the string calculator that Kata specified in Coding Dojo.

Any comments to improve would be amazing …

``````// StringCalculator.java

public class StringCalculator {

private float result;
private String customDelimiter;

private static final String DEFAULT_DELIMITER = ",";
private static final String NEWLINE = "n";
private static final String CUSTOM_DELIMITER_PREFIX = "/";
private static final String CUSTOM_DELIMITER_SUFFIX = NEWLINE;

StringCalculator() {
result = 0;
customDelimiter = "";
}

public String sum(String numbers) {
if (numbers.isEmpty())
return String.format("%.0f", result);

if (isInvalidLastCharacterIn(numbers))
return "Number expected but EOF found.";

if (numbers.startsWith(CUSTOM_DELIMITER_PREFIX))
numbers = setCustomDelimiter(numbers);

if (isNewlineAtInvalidPositionIn(numbers))
return String.format("Number expected but 'n' found at position %d.", numbers.lastIndexOf('n'));

if (containsNegative(numbers).length() > 0)
return String.format("Negative not allowed: %s", containsNegative(numbers));

calculateSumOf(getStringArray(numbers));

return hasDecimalPlaces() ? printFloat() : printInteger();
}

private boolean isInvalidLastCharacterIn(String numbers) {
return Character.digit(numbers.charAt(numbers.length() - 1), 10) < 0;
}

private boolean isNewlineAtInvalidPositionIn(String numbers) {
return numbers.lastIndexOf(NEWLINE) > numbers.lastIndexOf(DEFAULT_DELIMITER);
}

private StringBuilder containsNegative(String numbers) {
StringBuilder negativeNumbers = new StringBuilder();

for (String number : getStringArray(numbers))
if (Float.valueOf(number) < 0) negativeNumbers.append(number + ",");

boolean commaIsLastChar = negativeNumbers.length() > 0 && negativeNumbers.charAt(negativeNumbers.length() -1) == ',';

return commaIsLastChar ? negativeNumbers.deleteCharAt(negativeNumbers.length() - 1)
: negativeNumbers;
}

private String setCustomDelimiter(String numbers) {
int customDelimiterStart = numbers.lastIndexOf(CUSTOM_DELIMITER_PREFIX) + 1;
int customDelimiterEnd = numbers.indexOf(CUSTOM_DELIMITER_SUFFIX);

customDelimiter = numbers.substring(customDelimiterStart, customDelimiterEnd);

return numbers.substring(customDelimiterEnd + 1).replace(customDelimiter, DEFAULT_DELIMITER);
}

private String() getStringArray(String numbers) {
return numbers.replace(NEWLINE, DEFAULT_DELIMITER).split(DEFAULT_DELIMITER);
}

private void calculateSumOf(String() numbers) {
for (String number : numbers)
result = Float.sum(result, Float.parseFloat(number));
}

private boolean hasDecimalPlaces() {
return result % 1 != 0;
}

private String printFloat() {
return Float.toString((float) (Math.round(result * 100.0) / 100.0));
}

private String printInteger() {
return String.valueOf((int) result);
}
}

``````
``````// StringCalculatorShould.java

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class StringCalculatorShould {
@Test
public void
return_0_when_input_is_empty() {
assertEquals("0", given(""));
}

@Test
public void
return_3_when_input_is_1_2() {
assertEquals("3", given("1,2"));
}

@Test
public void
sum_floats_and_return_float() {
assertEquals("6.6", given("2.2,4.4"));
}

@Test
public void
treat_newLine_as_a_delimiter() {
assertEquals("6", given("1n2,3"));
}

@Test
public void
return_error_msg_when_newLine_at_invalid_position() {
assertEquals("Number expected but 'n' found at position 6.", given("1,2,5,n3"));
}

@Test
public void
return_error_msg_when_delimiter_at_last_position() {
assertEquals("Number expected but EOF found.", given("2,3,4.2,"));
}

@Test
public void
return_correct_sum_when_custom_delimiter_is_used() {
assertEquals("3", given("//;n1;2"));
assertEquals("3", given("//|n1|2"));
assertEquals("8", given("//@@n1@@2@@5"));
assertEquals("5", given("//sepn2sep3"));
}

@Test
public void
return_string_of_negative_numbers_when_negative_numbers_are_used_as_input() {
assertEquals("Negative not allowed: -1", given("-1,2"));
assertEquals("Negative not allowed: -4,-5", given("2,-4,-5"));
}

private String given(String number) {
StringCalculator stringCalculator = new StringCalculator();
return stringCalculator.sum(number);
}
}
``````

## Functional programming: analysis of kata strings in TypeScript

Customers make orders to a stockbroker as chains. The order can be simple or multiple.

Simple order type: Quote / blank space / Quantity / blank space / Price / blank space / Status where the Quote is formed by characters that are not blank spaces, Quantity is an int, Price double (with decimal point mandatory "."), The state is represented by the letter B (buy) or the letter S (sell).

Example:

``````"GOOG 300 542.0 B"
``````

A multiple order is the concatenation of simple orders with a comma between each one.

Example:

``````"ZNGA 1300 2.66 B, CLH15.NYM 50 56.32 B, OWW 1000 11.623 B, OGG 20 580.1 B"
``````

or (C)

"ZNGA 1300 2.66 B, CLH15.NYM 50 56.32 B, OWW 1000 11.623 B, OGG 20 580.1 B"

To facilitate the stockbroker, his task is to produce a chain of the type "Buy: b Sell: s" where bys are formatted & # 39; double & # 39; without decimal, b represents the total price of the shares purchased and s the total price of the shares sold.

Example:

Unfortunately, sometimes customers make mistakes. When you find errors in the orders, you must identify these poorly formed orders and produce a type string:

``````"Buy: b Sell: s; Badly formed nb: badly-formed 1st simple order ;badly-formed nth simple order ;"
``````

where nb is the number of malformed simple orders, b represents the total price of the shares purchased with the correct simple order and s the total price of the shares sold with the correct simple order.

Examples:

``````"Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;"
``````

I tried to follow a functional approach and the advice of Martin Fowler's Refactoring book and I'm curious to hear from you if you find this code easily readable and well designed and how I can improve.

Personally, I would have kept everything in a couple of non-static classes (StockOrder and StockOrderPart) to improve the usability of the code, but since the kata is tested with the units, I was forced to maintain parseStatement as a method of class G964.

## Unit tests – Bowling Kata in Java

I'm sharing my Kata bowling game score made in Java, it's available to anyone who wants to code it, review it.

``````BowlingGameScore class {

int private[] pinsKnockedDown = new int[21];
private int currentRoll = 0;

void roll (int pinsKnockedDown) {
this.pinsKnockedDown[currentRoll++] = pinsKnockedDown;
}

score int () {
int totalScore = 0;
int rollNumber = 0;

int frameScore;

if (isSpare (rollNumber)) {
frameScore = 10 + getSpareBonus (rollNumber);
rollNumber + = 2;

} else if (isStrike (pinsKnockedDown)[rollNumber])) {
frameScore = 10 + getStrikeBonus (rollNumber);
rollNumber ++;

} else {
frameScore = pinsKnockedDown[rollNumber] + pinsKnockedDown[rollNumber + 1];
rollNumber + = 2;
}

totalScore + = frameScore;
}

}

private int getStrikeBonus (int roll) {
back pinsKnockedDown[roll + 1] + pinsKnockedDown[roll + 2];
}

boolean privado isStrike (int roll) {
return roll == 10;
}

int private getSpareBonus (int roll) {
back pinsKnockedDown[roll + 2];
}

Private boolean isSpare (int roll) {
back pinsKnockedDown[roll] + pinsKnockedDown[roll + 1] == 10;
}}
``````

And its tests:

``````class BowlingGameScoreTest {
private BowlingGameScore game;

@Before Each
empty configuration () {
game = new BowlingGameScore ();
}

@Test
empty
game_no_pins_get_hit () {
rollMany (0, 20);

Assertions.assertEquals (0, game.score ());
}

@Test
empty
game_just_1_pin_get_hit () {
rollMany (1, 20);

Assertions.assertEquals (20, game.score ());
}

@Test
empty
game_with_1_spare () {
rollSpare ();
game.roll (3);
rollMany (0, 17);

Assertions.assertEquals (16, game.score ());
}

@Test
empty
game_with_1_strike () {
game.roll (10);
game.roll (3);
game.roll (4);
rollMany (0, 16);

Assertions.assertEquals (24, game.score ());
}

@Test
empty
game_of_strikes () {
rollMany (10, 12);

Assertions.assertEquals (300, game.score ());
}

@Test
empty
knockdown_nine_and_miss_ten_times () {

int firstRollPinsKnockedDown = 9;
int secondRollPinsKnockedDown = 0;
int repeatTimes = 10;
rollPair (repeatTimes, firstRollPinsKnockedDown, secondRollPinsKnockedDown);

Assertions.assertEquals (90, game.score ());
}

@Test
empty
knockdown_five_and_spare_ten_times_and_fice () {
rollPair (10, 5, 5);
game.roll (5);

Assertions.assertEquals (150, game.score ());
}

private void rollPair (int repeatTimes, int firstRollPinsKnockedDown, int secondRollPinsKnockedDown) {
for (int i = 0; i <repeatTimes; i ++) {
game.roll (firstRollPinsKnockedDown);
game.roll (secondRollPinsKnockedDown);
}
}

Empty private rollSpare () {
game.roll (5);
game.roll (5);
}

private void rollMany (int pins, int times) {
for (int i = 0; i <times; i ++) {
game.roll (pins);
}
}
``````

}

## Concept of character

For a new campaign I had the idea of ​​playing a John Wick-style construction that maximizes the effectiveness of hand crossbows with double grip. I want him to be a former mafia agent who escapes the law.

## Optimizing

I want to optimize this character for Get the maximum number of crossbow attacks per turn. I have the following restrictions:

• Use the standard matrix for the generation of statistics
• Optimize for a character that ends at level 10
• Make sure that my character is useful both in close combat and in the middle.
• Have the necessary mobility to avoid fighting big enemies from head to toe.
• The characteristics and multiclassification are fine.
• The content of any published WotC book (excluding UA) is allowed

What race, class levels and feats should I take to optimize this construction? Also, in what order should I take the levels and skills of level 1?

My hope is that my turn can replace an AOE spell by killing / almost killing several small enemies that are grouped together.

## l5r – Like a Mirumoto bushi, should I learn the Kata Spinning Blades?

I am planning to create a bus from Num Mirumoto school for L5R 5e, and I was surprised to see that the Rank 2 Kata that was available in rank 1 was the Iaijutsu Cut: Rising Blade and not the Spinning Blades Style.

After reading the text of the Kata Spinning Blades, I realized that to use the Kata, I should not use the technique of the Mirumoto school (which makes sense after all). But I also realized that this is the case with the Mirumoto master technique of rank 6 (which is quite similar to the rotating blades).

Here are my questions:

• Is it worth Spinning Blades, since I can not use it together with my school's technique (except in round 1 if I have initiative)?
• Although the Spinning Blade is a bit more difficult to perform and does not have the same effect, is not the Master Technique a bit useless if I have the Spinning Blades from Rank 2?

As a reminder:

Rotating knife technique: (p.180) When performing a Martial Art [Melee or Unarmed] In action, you can take advantage of as many opportunities as you can to watch your target to inflict damage with another weapon (the damage increases if the target is stunned).

Path of the Dragon (School Skill): (p.68) Whenever they attack you, you can use a weapon ready to inflict a malus on your attacker or get a bonus in your next attack against him. This weapon can not be used for attack actions until the end of your next turn.

Heart of the Dragon (Mastery Skill): (p.68) Once per round, when performing an attack action, you can use the opportunity to perform a Strike action with another weapon prepared.

## (Codewars Kata) Record cut memoised

(I'm not sure of the official CS name for the problem in question, so I just gave it the name of the kata).

# issue

## CLEAR CUTTER NEEDS YOUR HELP!

The Clear Cutter & # 39; s lumber company earns its money by optimizing the price-length ratio of each record they cut before selling them. An example of one of your price tables is included:

``````# So a price table p
p = [ 0,  1,  5,  8,  9, 10]

# You can imagine how:
# length i | 0 1 2 3 4 5 * in feet *
# price pi | 0 1 5 8 9 10 * in money *
``````

They hired an intern last summer to create a recursive function so that they can easily calculate the most profitable price for a record of length n using the price table p as follows:

``````def cut_log (p, n):
yes (n == 0):
return 0
q = -1
for i in rank (1, n + 1)
q = max (q, p[i] + cut_log (p, n-i))
come back
``````

An example of the work code:

``````# 5 feet = \$ 10, BUT 2 feet + 3 feet = 5 feet -> \$ 5 + \$ 8 = \$ 13 that is greater in value
``````

However, his senior software engineer realized that the number of recursive calls in the function gives him a horrible execution time of 2 ^ n (since this function is repeated in ALL the possibilities of 2 ^ n-1 for a record of length n).

Having discovered this problem just when he has arrived for his internship, he responsibly delegates the problem.

Using the power of Stack Overflow and Google, you want to create a solution that runs on Θ (n ^ 2) so that it does not take 5 hours to calculate the optimal price for a size 50 record. (It also suggests investigating the problem using the keywords on the labels)

(Note that if your algorithm is not efficient, you will try to observe 2 ^ 49 = 562949953421312 nodes instead of 49 ^ 2 = 2401 … The solution will fail automatically if it takes more than 6 seconds … what happens on the right around Log 23)

### Solution

``````def cut_log (p, n):
for i in range (2, len (p)):
P[i] = max (p[i-k] + p[k] for k in range ((i // 2) +1))
return p[n]
``````

Pass all the tests. I will put it for review because I am quite proud of it and of the experience that has shown me that, in general, some improvements must be made.

## java – Mix of strings Code Wars Kata

Problem Statement

``````Given the two chains s1 and s2, we want to visualize how different the two chains are. We will only consider the lowercase letters (from A to Z). First, let's count the frequency of each lowercase letter in s1 and s2.

s1 = "A yyyy bb c"

s2 = "& aaa bbb c d"

s1 is 4 & # 39 ;, 2 & # 39; b & # 39 ;, 1 & # 39; c & # 39; c & # 39;

s2 is 3 & # 39 ;, 3 & # 39 ;, 1 & # 39 ;, 1 & # 39; d & # 39;

Then the maximum for & # 39; a & # 39; in s1 and s2 is 4 from s1; the maximum for & # 39; b & # 39; is 3 of s2. In what follows we will not consider the letters when the maximum of their occurrences is less than or equal to 1.
We can resume the differences between s1 and s2 in the following string: "1: yyyy / 2: bbb" where 1 in 1: yyyy means string s1 and yyyy because the maximum for a is 4. In the same way 2: bbb represents the string s2 and bbb because the maximum for b is 3.
The task is to produce a string in which each lowercase letter of s1 or s2 appears as many times as many if this maximum is strictly greater than 1; These letters will be preceded by the number of the chain where they will appear with their maximum value and :. If the maximum is in s1 and in s2, the prefix is ​​=:.

In the result, substrings (a substring is for example 2: nnnnn or 1: hhh; contains the prefix) will be in descending order of their length and when they have the same length ordered in ascending lexicographical order (letters and digits - more precisely ordered per code point); The different groups will be separated by & # 39; / & # 39 ;. See examples and "Sample tests".
Hopefully, other examples can clarify this.
s1 = "my & friend & Paul has heavy hats! &"
s2 = "my friend John has many friends and"
mix (s1, s2) -> "2: nnnnn / 1: yyyy / 1: hhh / 2: mmm / 2: yyy / 2: dd / 2: ff / 2: ii / 2: rr / =: ee / = : H.H "

s1 = "mmmmm m nnnnn and & friend & Paul has heavy hats! &"
s2 = "my frie n d Joh n has ma n y ma n and frie n ds n &"
mix (s1, s2) -> "1: mmmmmm / =: nnnnnn / 1: yyyy / 1: hhh / 2: yyy / 2: dd / 2: ff / 2: ii / 2: rr / =: ee / = : H.H "

s1 = "Are the children at home? aaaaa fffff"
s2 = "Yes, they are here! aaaaa fffff"
mix (s1, s2) -> "=: aaaaaa / 2: eeeee / =: fffff / 1: tt / 2: rr / =: hh"
Note for Swift, R, PowerShell
The prefix =: is replaced by E:

s1 = "mmmmm m nnnnn and & friend & Paul has heavy hats! &"
s2 = "my frie n d Joh n has ma n y ma n and frie n ds n &"
mix (s1, s2) -> "1: mmmmmm / E: nnnnnn / 1: yyyy / 1: hhh / 2: yyy / 2: dd / 2: ff / 2: ii / 2: rr / E: ee / E : H.H "
``````

Here is my solution:

``````public class StringMixKata {

Private static final set uniqueAlphabets = new LinkedHashSet <> ();
Private static end string LOWER_CASE_ALPHABET_NEGATED_REGEX = "[^a-z]+ ";
Final static private string EQUALITY = "=";
Private static end string COLON = ":";
Private static end string FORWARD_SLASH = "/";
Private static end string EMPTY_STRING = "";
Private static end string EMPTY_CHARACTER = " 0";
static end private int MINIMUM_FREQUENCY_REQUIRED = 2;

String static private StringMix (String s1, String s2) {
s1 = removeAllCharactersExceptLowerCaseAlphabets (s1);
s2 = removeAllCharactersExceptLowerCaseAlphabets (s2);
Map s1CharacterFrequencyMap = calculateFrequency forEachAlphabetAndAddEachAlphabetToSetOfUnique (s1);
Map s2CharacterFrequencyMap = calculateFrequency forEachAlphabetAndAddEachAlphabetToSetOfUnique (s2);
List finalList = createListOfFrequenciesForFinalString (s1CharacterFrequencyMap, s2CharacterFrequencyMap);
return formatString (finalList);
}

Private static string removeAllCharactersExceptLowerCaseAlphabets (final string entry) {
return input.replaceAll (LOWER_CASE_ALPHABET_NEGATED_REGEX, EMPTY_STRING);
}

/ **
* Calculate the frequency of each character in the string and return the frequencies
* of the characters as a {@link Map} with the characters like the key and the frequency
* as the value of the map. This function also adds each character to a {@link Set} of Unique
* alphabets
* @param input
* @return Map
* /
Static private map CalculateFrequencyForEachAlphabetAndAddEachAlphabetToSetOfUnique (final entry of String) {
Map alphabetFrequency = new HashMap <> ();
for (char alphabet: input.toCharArray ()) {
if (alphabetFrequency.containsKey (alphabet)) {
int frequency = alphabetFrequency.get (alphabet) +1;
alphabetFrequency.put (alphabet, frequency);
}plus{
alphabetFrequency.put (alphabet, 1);
}
}
return alphabetFrequency;
}

/ **
* Create a list of objects {@link AlphabetFrequencyAndOrigin}.
* The final list contains the most frequent alphabets with their origin.
* This list only contains elements for each alphabet.
* For example if there is a character & # 39; a & # 39 ;. Now a map has a frequency of 3 and the map Other has
* a frequency of 4. Therefore, any entry will be added to the return list with a frequency of 4 with the origin
* Set as the last. Before returning the list, this function will also sort the list according to the frequencies
* of the alphabets. If the frequencies are equal for two alphabets, then the elements would be compared alphabetically.
* @param s1CharacterFrequencyMap
* @param s2CharacterFrequencyMap
* @return List
* /
Private static list createListOfFrequenciesForFinalString (final map s1CharacterFrequencyMap, final map s2CharacterFrequencyMap) {
final list finalList = new LinkedList <> ();
for (alphabet of characters: uniqueAlfabetos) {
if (bothTheMapsContainTheAlphabetWithSameFrequency (s1CharacterFrequencyMap, s2CharacterFrequencyMap, alphabet)) {
if (s1CharacterFrequencyMap.get (alphabet) <MINIMUM_FREQUENCY_REQUIRED) continues;
finalList.add (new AlphabetFrequencyAndOrigin (null, alphabet, s1CharacterFrequencyMap.get (alphabet)));
}
if (bothTheMapsContainTheAlphabet (s1CharacterFrequencyMap, s2CharacterFrequencyMap, alphabet)) {
if (s1CharacterFrequencyMap.get (alphabet) < s2CharacterFrequencyMap.get(alphabet)){
}
if(s1CharacterFrequencyMap.get(alphabet) > s2CharacterFrequencyMap.get (alphabet)) {
finalList.add (new AlphabetFrequencyAndOrigin (1, alphabet, s1CharacterFrequencyMap.get (alphabet)));
}
}plus{
if (s1CharacterFrequencyMap.get (alphabet)! = null && s1CharacterFrequencyMap.get (alphabet)> = MINIMUM_FREQUENCY_REQUIRED) finalList.add (new AlphabetFrequencyAndOrigin (1, alphabet, s1CharacterFrequencyMap.get (alphabet));
if (s2CharacterFrequencyMap.get (alphabet)! = null && s2CharacterFrequencyMap.get (alphabet)> = MINIMUM_FREQUENCY_REQUIRED) finalList.add (new AlphabetFrequencyAndOrigin (2, alphabet, s2CharacterFrequencyMap.get (alphabet));
}

}
Collections.sort (finalList);
return finalList;
}

static boolean private, bothMapsContainTheAlphabet (final map s1, final map s2, final character alphabet) {
return s1.containsKey (alphabet) && s2.containsKey (alphabet);
}

static static boolean, bothMapsContainTheAlphabetWithSameFrequency (final map) s1, final map s2, final character alphabet) {
return both TheMapsContainTheAlphabet (s1, s2, alphabet)? s1.get (alphabet) .equals (s2.get (alphabet)): Boolean.FALSE;
}

/ **
* Create a string where each alphabet is denoted by its origin & # 39;: & # 39; number of times the character is repeated. Y
* Each character is linked by & # 39; / & # 39 ;. Then an example would be:
* 1: mmmmmm / =: nnnnnn / 1: yyyy / 1: hhh / 2: yyy / 2: dd / 2: ff / 2: ii / 2: rr / =: ee / =: ss.

*
* The equality character means that the origin is null.
* @param finalSet
* @he came back
* /
String of private static string format (final list finalSet) {
StringBuilder builder = new StringBuilder ();
for (AlphabetFrequencyAndOrigin item: finalSet) {
if (item.getOrigin () == null) builder.append (EQUALITY);
else builder.append (item.getOrigin ());
constructor.append (COLON);
builder.append (repeatAlphabet (item.getAlphabet (), item.getFrequency ()));
builder.append (FORWARD_SLASH);
}
constructor = removeTheLastForwardSlash (constructor);
returns builder.toString ();
}

/ **
* This method returns a string "yyyy" if it happens & # 39; a & # 39; as the character and 4 as the frequency. This method
* is an implementation of the character multiplication operation. Copied the implementation from
*
* Simple way to repeat a string in java.   . This is really smart.
* @param alphabet
* @param frequency
* @return String
* /
Private static string repeatAlphabet (final character alphabet, final int frequency) {
returns new string (new char[frequency]) .replace (EMPTY_CHARACTER, String.valueOf (alphabet));
}

StringBuilder static private removeTheLastForwardSlash (generator of StringBuilder final) {
return builder.replace (builder.lastIndexOf (FORWARD_SLASH), builder.length (), EMPTY_STRING);
}

};

/ **
* A class that contains the number of String to which the alphabet belongs and the frequency of the alphabet.
* This is just a container class that also helps classify by implementing the {@link Comparable} interface.
* If the origin is set to null, it is assumed that the alphabet is present in both the compared string.
*
* /
The AlphabetFrequencyAndOrigin class implements Comparable{

private final whole origin;

Private final character alphabet;

Private final integer frequency;

Public AlphabetFrequencyAndOrigin (origin of integer, character alphabet, frequency of integer) {
this.original = origin;
this.alphabet = alphabet;
this.frequency = frequency;
}

Integer public getOrigin () {
origin of return;
}

Public character getAlphabet () {
return alphabet
}

Public integer getFrequency () {
return frequency
}

@Cancel
public int compareTo (AlphabetFrequencyAndOrigin o) {
if (origin == null && o.getOrigin () == null && frequency.compareTo (o.getFrequency ()) == 0) return alphabet.compareTo (o.getAlphabet ());
return frequency.compareTo (o.getFrequency ()) == 0? alphabet.compareTo (o.getAlphabet ()): o.getFrequency (). compareTo (frequency);
}

}
``````

I programmed the solution in Java 7. The reason why I did it is because I have a hard time understanding the flows and the provider, the concepts of consumers in Java 8 (I do not know why Java is becoming a functional programming language) . I know that the solution can be drastically improved in java 8.

The order of the chains in the output would not match some sample inputs provided. The author specifically said lexicographical order and wrote the `compare with` Work that way only. Am I doing something wrong here or have I misinterpreted something?

Is there any space for improvements here? Is there something wrong with my approach? I need your opinions.