APL/DEV 3.2/TP04/Derecursivation/Derecursif.java
2022-10-26 11:13:11 +02:00

35 lines
697 B
Java

public class Derecursif {
public static int f(int n) {
ArrayPile<Integer> pile = new ArrayPile<>();
pile.addFirst(n);
int result = 0;
while (pile.size() > 0) {
n = pile.pollFirst();
switch (n) {
case 0:
break;
case 1:
result += 1;
break;
default:
pile.addFirst(n / 2);
pile.addFirst(n / 3);
break;
}
}
return result;
}
public static void main(String[] args) {
System.out.println(f(150));
}
}