Elegant Project Euler Solution
ixid
adamsibson at gmail.com
Mon Nov 4 10:37:31 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 ;)
I'm not sure that using pre-rolled library functions is entirely
the point of Project Euler. To get the most out of it make your
own functions for tasks that are core to the problem. The
problems are clearly structured in a way that leads toward
building your own library from puzzle to puzzle and realising
when you can reuse functions from previous problems.
More information about the Digitalmars-d
mailing list