Skip to content

Commit e6bc62f

Browse files
committed
commit
1 parent 0ca960e commit e6bc62f

9 files changed

Lines changed: 79 additions & 17 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding//src/calculator/sum/Calculatro.java=UTF-8
883 Bytes
Binary file not shown.
693 Bytes
Binary file not shown.

bin/nodeExam/Node.class

-71 Bytes
Binary file not shown.
1.69 KB
Binary file not shown.

src/nodeExam/Node.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,13 @@ public Node(int value, Node left, Node right) {
1616
this.right = right;
1717
}
1818

19-
public Node find (int v){
20-
21-
Node n = new Node();
22-
if(v == this.value) {return this;}
23-
24-
if (v < this.value && this.left != null) {
25-
if(n.value == v) return n;
26-
n = this.left.find(v);
19+
public Node find(int v) {
20+
Node current = this;
21+
22+
while (current != null && current.value != v) {
23+
current = v < current.value ? current.left : current.right;
2724
}
28-
29-
if (v > this.value && this.right != null) {
30-
if(n.value == v) return n;
31-
n = this.right.find(v);
32-
33-
}
34-
35-
return n;
36-
25+
return current;
3726
}
3827

3928
}

src/reshape_string/reshap1.PNG

103 KB
Loading

src/reshape_string/reshap2.PNG

38 KB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package termesConsecutivesFibonacci;
2+
3+
public class Principale {
4+
5+
public static void main(String[] args) {
6+
System.out.println("starting ...");
7+
int result = 0;
8+
int n = 21;
9+
int m = 34;
10+
int i = 0;
11+
int j = 0;
12+
if (!isFibonacci(n) || !isFibonacci(m))
13+
result = 0;
14+
15+
else {
16+
while (fibOptimized(i) < n) {
17+
if (fibOptimized(i) != n) {
18+
i++;
19+
}
20+
if (fibOptimized(i) == n)
21+
break;
22+
}
23+
24+
while (fibOptimized(j) < m) {
25+
{
26+
if (fibOptimized(j) != m)
27+
28+
j++;
29+
}
30+
if (fibOptimized(j) == m)
31+
break;
32+
}
33+
34+
if ((i + 1 == j || i == j) && i != 0)
35+
result = 1;
36+
}
37+
System.out.println("le resultat est :" + result);
38+
}
39+
40+
public static int fibOptimized(int n) {
41+
if (n == 0)
42+
return 0;
43+
if(n==1)
44+
return 1;
45+
int prev = 0, res = 1, next;
46+
for (int i = 1; i < n; i++) {
47+
next = res + prev;
48+
prev = res;
49+
res = next;
50+
}
51+
return res;
52+
}
53+
54+
55+
56+
/**
57+
*
58+
* @param w
59+
* @return boolean value : true if w is in fibonacci false if it's not
60+
*/
61+
static boolean isFibonacci(int w) {
62+
double X1 = 5 * Math.pow(w, 2) + 4;
63+
double X2 = 5 * Math.pow(w, 2) - 4;
64+
65+
long X1_sqrt = (long) Math.sqrt(X1);
66+
long X2_sqrt = (long) Math.sqrt(X2);
67+
68+
return (X1_sqrt * X1_sqrt == X1) || (X2_sqrt * X2_sqrt == X2);
69+
}
70+
71+
}

0 commit comments

Comments
 (0)