Elegant Project Euler Solution
Jonathan Marler
johnnymarler at gmail.com
Mon Nov 4 18:18:53 UTC 2019
On Sunday, 3 November 2019 at 19:51:14 UTC, Leonhard Euler wrote:
> Hi all,
> Just wanted to share a very elegant solution for Project Euler,
> problem #24.
>
> This is the problem:
>
> A permutation is an ordered arrangement of objects. For
> example, 3124 is one possible permutation of the digits 1, 2, 3
> and 4. If all of the permutations are listed numerically or
> alphabetically, we call it lexicographic order. The
> lexicographic permutations of 0, 1 and 2 are:
>
> 012 021 102 120 201 210
>
> What is the millionth lexicographic permutation of the digits
> 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
>
> And my solution:
>
> ```
> import std;
>
> void main() {
> iota(10).array.nthPermutation(999999).writeln();
> }
> ```
>
> Know thy standard library ;)
Very nice. The D standard library has alot of useful
functionality. I myself often make the mistake of not knowing
what's in it and write my own implementation of things that are
already available.
More information about the Digitalmars-d
mailing list