Prime triangle: Difference between revisions

Content added Content deleted
m (Minor optimization to Java code - see discussion page)
m (Minor optimization to Rust code - see discussion page)
Line 931: Line 931:
return is_prime(a[0] + a[1]);
return is_prime(a[0] + a[1]);
}
}
for i in 1..a.len() - 1 {
for i in (1..a.len() - 1).step_by(2) {
if is_prime(a[0] + a[i]) {
if is_prime(a[0] + a[i]) {
a.swap(i, 1);
a.swap(i, 1);
Line 950: Line 950:
}
}
} else {
} else {
for i in 1..a.len() - 1 {
for i in (1..a.len() - 1).step_by(2) {
if is_prime(a[0] + a[i]) {
if is_prime(a[0] + a[i]) {
a.swap(i, 1);
a.swap(i, 1);
Line 1,018: Line 1,018:
1 1 1 1 1 2 4 7 24 80 216 648 1304 3392 13808 59448 155464 480728 1588162
1 1 1 1 1 2 4 7 24 80 216 648 1304 3392 13808 59448 155464 480728 1588162


Elapsed time: 711 milliseconds
Elapsed time: 674 milliseconds
</pre>
</pre>