Fusc sequence: Difference between revisions

Added Processing code
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Added Processing code)
Line 2,102:
19,573,419 : 103,682
</pre>
 
=={{header|Processing}}==
<lang processing>void setup() {
println("First 61 terms:");
for (int i = 0; i < 60; i++) {
print(fusc(i) + " ");
}
println(fusc(60));
println();
println("Sequence elements where number of digits of the value increase:");
int max_len = 0;
for (int i = 0; i < 700000; i++) {
int temp = fusc(i);
if (str(temp).length() > max_len) {
max_len = str(temp).length();
println("(" + i + ", " + temp + ")");
}
}
}
 
int fusc(int n) {
if (n <= 1) {
return n;
} else if (n % 2 == 0) {
return fusc(n / 2);
} else {
return fusc((n - 1) / 2) + fusc((n + 1) / 2);
}
}</lang>
{{out}}
<pre>First 61 terms:
0 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 1 5 4 7 3 8 5 7 2 7 5 8 3 7 4 5 1 6 5 9 4 11 7 10 3 11 8 13 5 12 7 9 2 9 7 12 5 13 8 11 3 10 7 11 4
 
Sequence elements where number of digits of the value increase:
(0, 0)
(37, 11)
(1173, 108)
(35499, 1076)
(699051, 10946)</pre>
 
=={{header|Prolog}}==
Anonymous user