To learn I’m solving some Euler Problems in Rust (and I’m having good headaches. Rust is more fun than a Rubik cube).

This is a simple D language solution of the problem #24 (What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?):

```
import std.algorithm, std.array, std.string;
size_t fac(in size_t n) @nogc { return n ? n * fac(n - 1) : 1; }
void n_lexi_perm(ubyte[] xs, size_t n) @nogc {
while (!xs.empty) {
immutable m = fac(xs.length - 1);
immutable y = n / m;
bringToFront(xs[0 .. y], xs[y .. y + 1]);
xs.popFront;
n %= m;
}
}
void main() {
char[10] s = "0123456789";
n_lexi_perm(s.representation, 999999);
assert(s == "2783915460");
}
```

And this is the solution I’ve managed to write in Rust so far:

```
#![feature(iter_arith)]
fn main() {
fn n_lexi_perm(xs: &mut [u8], n: usize) {
if xs.is_empty() { return; }
let m: usize = (1 .. xs.len()).product();
let y = n / m;
xs[0 .. y + 1].reverse();
xs[1 .. y + 1].reverse();
n_lexi_perm(&mut xs[1 ..], n % m);
}
let mut s = *b"0123456789";
n_lexi_perm(&mut s, 999_999);
assert_eq!(&s, b"2783915460");
}
```

Is such Rust code good? Do you have suggestions?

Some of the problems I’ve found:

- I was unable to make the Rust version iterative. Can you show me how to do it?
- I was unable to find a bringToFront algorithm in the Rust std lib, it’s called “rotate” in C++:

http://dlang.org/phobos/std_algorithm_mutation.html#.bringToFront

http://www.cplusplus.com/reference/algorithm/rotate/

If this algorithm is not present in the Rust std lib then I suggest to add it, because it’s quite fundamental and famous.

Thank you for the answers