Skip to content

Commit b9e69bd

Browse files
committed
Updated Objetcs code, added Deficient, Abundant and Perfect numbers
1 parent 7313ae6 commit b9e69bd

12 files changed

+448
-168
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Abundant extends NeilJames{
2+
3+
String description(){
4+
return "A number n is abundant if the sum of divisors is greather than n.";
5+
}
6+
7+
int compute(int i){
8+
if(i<=0)
9+
return -1;
10+
return abundant(i);
11+
}
12+
13+
/**
14+
* True if i is abundant
15+
*/
16+
boolean isNeilJames(int i){
17+
if(sigmaDivisors(i)>i)
18+
return true;
19+
return false;
20+
}
21+
22+
/**
23+
* Return i abundant number
24+
*/
25+
int abundant(int i){
26+
int j=1;
27+
for(int numberOfAbundants=0; numberOfAbundants<i; j++){
28+
if(isNeilJames(j)){
29+
numberOfAbundants++;
30+
}
31+
}
32+
return j-1;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Deficient extends NeilJames{
2+
3+
String description(){
4+
return "A number n is deficient if the sum of divisors is less than n.";
5+
}
6+
7+
int compute(int i){
8+
if(i<6 && i>0)
9+
return i;
10+
if(i<=0)
11+
return -1;
12+
return sigma(deficients(i));
13+
}
14+
15+
/**
16+
* True if i is deficient
17+
*/
18+
boolean isNeilJames(int i){
19+
if(sigmaDivisors(i)<i)
20+
return true;
21+
return false;
22+
}
23+
24+
/**
25+
* Sum of an ArrayList
26+
*/
27+
int sigma(ArrayList<Integer> defi){
28+
int sum=0;
29+
for(int j=0; j<defi.size(); j++)
30+
sum+=defi.get(j);
31+
return sum;
32+
}
33+
34+
/**
35+
* ArrayList for sigma and obtain i sequence number
36+
*/
37+
ArrayList deficients(int i){
38+
ArrayList<Integer> defi = new ArrayList<Integer>();
39+
defi.add(0, 0);
40+
defi.add(1, 1);
41+
for(int j=2; j<=i; j++){
42+
if(isNeilJames(sigma(defi)+1)){
43+
defi.add(j,1);
44+
} else {
45+
defi.add(j,2);
46+
}
47+
}
48+
return defi;
49+
}
50+
}

IntegerSequencesObjects/Fibonacci.pde IntegerSequencesOBJECTS/Processing/Fibonacci.pde

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class fibonacci extends Sequence{
1+
class Fibonacci extends Sequence{
22
String author(){
33
return "Leonardo Bonacci";
44
}
@@ -66,7 +66,6 @@ class fibonacci extends Sequence{
6666
void dibujoRect(int i, float nW, float nH){
6767
stroke(0,100,100);
6868
int a=compute(i);
69-
float textX, textY;
7069
textSize(map(a,0,compute(n),5,50));
7170
switch(i%4){
7271
case 1:

IntegerSequencesObjects/Golomb.pde IntegerSequencesOBJECTS/Processing/Golomb.pde

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class golomb extends Sequence{
1+
class Golomb extends Sequence{
22

33
String author(){
44
return "Solomon Wolf Golomb";
@@ -17,6 +17,7 @@ class golomb extends Sequence{
1717
}
1818

1919
void display(int n){
20+
textSize(50);
2021
int nAct=1;
2122
float div;
2223
float sizeWidth;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Objects declaration
2+
Fibonacci fiboSeq;
3+
Golomb goloSeq;
4+
Juggler juggSeq;
5+
Deficient defiSeq;
6+
Abundant abunSeq;
7+
Perfect perfSeq;
8+
9+
int n=1, serie, mode, counter;
10+
11+
void setup() {
12+
size(1400, 800);
13+
background(0);
14+
colorMode(HSB, 360, 100, 100);
15+
noFill();
16+
smooth();
17+
// Object init
18+
fiboSeq = new Fibonacci();
19+
goloSeq = new Golomb();
20+
juggSeq = new Juggler();
21+
defiSeq = new Deficient();
22+
abunSeq = new Abundant();
23+
perfSeq = new Perfect();
24+
}
25+
26+
void draw() {
27+
background(0);
28+
dibujoSerie();
29+
}
30+
31+
void dibujoSerie() {
32+
switch(serie) {
33+
case 0: //Implementación gráfico de serie Fibonacci
34+
textSize(12);
35+
textAlign(LEFT);
36+
text("Fibonacci", 0, 11);
37+
switch(mode) {
38+
case 0:
39+
for (int i=1; i<=n; i++)
40+
fiboSeq.display(i);
41+
counter=0;
42+
break;
43+
case 1:
44+
fiboSeq.barChart(n);
45+
break;
46+
case 2:
47+
fiboSeq.lineChart(n);
48+
break;
49+
case 3:
50+
fiboSeq.curveFitting(n);
51+
break;
52+
}
53+
break;
54+
case 1: //Implementación gráfico de serie Golomb
55+
textSize(12);
56+
textAlign(LEFT);
57+
text("Golomb", 0, 11);
58+
switch(mode) {
59+
case 0:
60+
goloSeq.display(n);
61+
break;
62+
case 1:
63+
goloSeq.barChart(n);
64+
break;
65+
case 2:
66+
goloSeq.lineChart(n);
67+
break;
68+
case 3:
69+
goloSeq.curveFitting(n);
70+
break;
71+
}
72+
break;
73+
case 2: //Implementación gráfico de serie Juggler
74+
textSize(12);
75+
textAlign(LEFT);
76+
text("Juggler", 0, 11);
77+
switch(mode) {
78+
case 0:
79+
juggSeq.display(n);
80+
break;
81+
case 1:
82+
juggSeq.barChart(n);
83+
break;
84+
case 2:
85+
juggSeq.lineChart(n);
86+
break;
87+
case 3:
88+
juggSeq.curveFitting(n);
89+
break;
90+
}
91+
break;
92+
case 3: //Implementación gráfico de serie Deficient
93+
textSize(12);
94+
textAlign(LEFT);
95+
text("Deficient", 0, 11);
96+
switch(mode) {
97+
case 0:
98+
defiSeq.display(n);
99+
break;
100+
case 1:
101+
defiSeq.barChart(n);
102+
break;
103+
case 2:
104+
defiSeq.lineChart(n);
105+
break;
106+
case 3:
107+
defiSeq.curveFitting(n);
108+
break;
109+
}
110+
break;
111+
case 4: //Implementación gráfico de serie Abundant
112+
textSize(12);
113+
textAlign(LEFT);
114+
text("Abundant", 0, 11);
115+
switch(mode) {
116+
case 0:
117+
abunSeq.display(n);
118+
break;
119+
case 1:
120+
abunSeq.barChart(n);
121+
break;
122+
case 2:
123+
abunSeq.lineChart(n);
124+
break;
125+
case 3:
126+
abunSeq.curveFitting(n);
127+
break;
128+
}
129+
break;
130+
case 5: //Implementación gráfico de serie Perfect
131+
textSize(12);
132+
textAlign(LEFT);
133+
text("Perfect", 0, 11);
134+
switch(mode) {
135+
case 0:
136+
perfSeq.display(n);
137+
break;
138+
case 1:
139+
perfSeq.barChart(n);
140+
break;
141+
case 2:
142+
perfSeq.lineChart(n);
143+
break;
144+
case 3:
145+
perfSeq.curveFitting(n);
146+
break;
147+
}
148+
break;
149+
}
150+
}
151+
152+
void keyPressed() {
153+
// Object use:
154+
switch(key) {
155+
case '>':
156+
serie=(serie+1) % 6;
157+
break;
158+
case '<':
159+
if (serie==0) {
160+
serie=5;
161+
} else {
162+
serie--;
163+
}
164+
break;
165+
case '+':
166+
n++;
167+
/*println(n + " term Fibonacci value is: " + fiboSeq.compute(n));
168+
println(n + " term Golomb value is: " + goloSeq.compute(n));
169+
println(n + " term Juggler value is: " + Arrays.toString(juggSeq.juggler(n)));
170+
println(n + " term Deficient value is: " + defiSeq.compute(n));
171+
println(n + " term Abundant value is: " + abunSeq.compute(n));
172+
println(n + " term Perfect value is: " + perfSeq.compute(n));*/
173+
break;
174+
case '-':
175+
if (n>1) {
176+
n--;
177+
/*println(n + " term Fibonacci value is: " + fiboSeq.compute(n));
178+
println(n + " term Golomb value is: " + goloSeq.compute(n));
179+
println(n + " term Juggler value is: " + Arrays.toString(juggSeq.juggler(n)));
180+
println(n + " term Deficient value is: " + defiSeq.compute(n));
181+
println(n + " term Abundant value is: " + abunSeq.compute(n));
182+
println(n + " term Perfect value is: " + perfSeq.compute(n));*/
183+
}
184+
break;
185+
case 'p':
186+
fiboSeq.printFirstN(n, "Fibonacci");
187+
goloSeq.printFirstN(n, "Golomb");
188+
juggSeq.printFirstN(n, "Juggler (max value of array)");
189+
defiSeq.printFirstN(n, "Deficient");
190+
abunSeq.printFirstN(n, "Abundant");
191+
perfSeq.printFirstN(n, "Perfect");
192+
break;
193+
case '.':
194+
mode= (mode+1) % 4;
195+
break;
196+
case ',':
197+
if (mode==0) {
198+
mode=3;
199+
} else {
200+
mode--;
201+
}
202+
break;
203+
}
204+
}

IntegerSequencesObjects/Juggler.pde IntegerSequencesOBJECTS/Processing/Juggler.pde

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class juggler extends Sequence{
1+
class Juggler extends Sequence{
22

33
String author(){
44
return "Clifford Alan Pickover";
@@ -56,6 +56,7 @@ class juggler extends Sequence{
5656
}
5757

5858
void display(int n){
59+
textSize(15);
5960
int tam=tamArr(n);
6061
int arr[]=new int[tam];
6162
arr=juggler(n);

0 commit comments

Comments
 (0)