Skip to content

Commit

Permalink
Well, it seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
jEUGENEdev committed Sep 23, 2022
1 parent 0524ed7 commit 98159a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/main/java/org/math/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.math;

import org.math.exc.ArgsFailException;
import org.math.calc.Group;
import org.math.exc.ArgsFailException;

import java.util.Scanner;

Expand All @@ -10,9 +10,18 @@ public static void main(String[] args) throws ArgsFailException {
try(Scanner scanner = new Scanner(System.in)) {
String expr = scanner.nextLine();
G g = checkIsGroups(expr);
if(!g.is())
if (!g.is())
throw new ArgsFailException();
Group group = new Group(g.groups());
group.start();
System.out.printf("""
Result in cycle note:
%s
Result in table note
%s""", group.getCycleNoteResult(), group.getTableNoteResult());
}
}

Expand Down
29 changes: 24 additions & 5 deletions src/main/java/org/math/calc/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
public class Group {
public static Pattern pGroup = Pattern.compile("(\\((\\d+\\s?)+\\))+");
private String[] groups;
private String result;
private Integer[][] result;

public Group(String[] groups) {
this.groups = groups;
equalityOfSets();
}

private void equalityOfSets() {
public void start() {
List<Integer[][]> symGroupsMult = new ArrayList<>();
for (String group : groups) {
String[] groupOne = group
Expand All @@ -23,7 +22,9 @@ private void equalityOfSets() {
.split("\\*");
symGroupsMult.add(buildTable(groupOne));
}
System.out.println(toCycleNote(multiplication(symGroupsMult.get(0), symGroupsMult.get(1))));
result = symGroupsMult.get(0);
for (int i = 1; i < symGroupsMult.size(); i++)
result = multiplication(result, symGroupsMult.get(i));
}

private Integer[][] buildTable(String[] cycleNoteGroup) {
Expand Down Expand Up @@ -73,7 +74,7 @@ private int searchDisplayFromA(int a, Integer[][] symGroupTable) {
private String toCycleNote(Integer[][] symGroupTable) {
StringBuilder cycleNote = new StringBuilder();
Set<Integer> tracking = new HashSet<>();
for (int i = 0; i < symGroupTable.length; i++) {
for (int i = 0; i < symGroupTable[0].length; i++) {
int first = symGroupTable[0][i];
if (tracking.contains(first))
continue;
Expand All @@ -91,4 +92,22 @@ private String toCycleNote(Integer[][] symGroupTable) {
}
return cycleNote.toString();
}

private String toTableNote(Integer[][] symGroupTable) {
StringBuilder note = new StringBuilder();
for (Integer[] integers : symGroupTable) {
for (Integer integer : integers)
note.append(integer).append(' ');
note.deleteCharAt(note.length() - 1).append("\n");
}
return note.toString();
}

public String getCycleNoteResult() {
return toCycleNote(result);
}

public String getTableNoteResult() {
return toTableNote(result);
}
}

0 comments on commit 98159a9

Please sign in to comment.