forked from kalmar/DALGLI0
Dodano brakujący plik
This commit is contained in:
parent
c9e9b68a89
commit
084753cc47
43
zad1/Ring.java
Normal file
43
zad1/Ring.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user