Zadanie 1 i 2 #38

Open
s416042 wants to merge 6 commits from s416042/DALGLI0:master into master
Showing only changes of commit 084753cc47 - Show all commits

43
zad1/Ring.java Normal file
View File

@ -0,0 +1,43 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.IntStream;
public class Ring {
private int n;
Ring(int n) {
this.n = n;
}
public String findRingDetails() {
int[] reversibleElements = getReversibleElements();
int[] zeroDivisors = getZeroDivisors();
Set nilpotentElements = getNilpotentElements(zeroDivisors);
int[] idempotentElements = getIdempotentElements();
return "[" + Arrays.toString(reversibleElements) + ", " + Arrays.toString(zeroDivisors) + ", " + nilpotentElements + ", " + Arrays.toString(idempotentElements) + "]";
}
private int[] getReversibleElements() {
return IntStream.rangeClosed(0, n - 1).filter(k -> NWDCalculator.findNWD(k, n) == 1).toArray();
}
private int[] getZeroDivisors() {
return IntStream.rangeClosed(0, n - 1).filter(k -> NWDCalculator.findNWD(k, n) > 1).toArray();
}
private Set getNilpotentElements(int[] zeroDivisors) {
Set<Integer> nilpotentElements = new HashSet<>();
for (int i = 0; i < n; i++) {
for (int i1 : zeroDivisors) {
if (Math.pow(i1, i) % n == 0)
nilpotentElements.add(i1);
}
}
return nilpotentElements;
}
private int[] getIdempotentElements() {
return IntStream.rangeClosed(0, n - 1).filter(k -> k * k % n == k).toArray();
}
}