]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/024/024.factor
project-euler: Rewrap, update links, add copyrights, tests
[factor.git] / extra / project-euler / 024 / 024.factor
1 ! Copyright (c) 2008 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: math.combinatorics project-euler.common sequences ;
4 IN: project-euler.024
5
6 ! https://projecteuler.net/problem=24
7
8 ! DESCRIPTION
9 ! -----------
10
11 ! A permutation is an ordered arrangement of objects. For
12 ! example, 3124 is one possible permutation of the digits 1, 2,
13 ! 3 and 4. If all of the permutations are listed numerically or
14 ! alphabetically, we call it lexicographic order. The
15 ! lexicographic permutations of 0, 1 and 2 are:
16
17 !     012   021   102   120   201   210
18
19 ! What is the millionth lexicographic permutation of the digits
20 ! 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
21
22
23 ! SOLUTION
24 ! --------
25
26 : euler024 ( -- answer )
27     999999 10 <iota> permutation digits>number ;
28
29 ! [ euler024 ] 100 ave-time
30 ! 0 ms ave run time - 0.27 SD (100 trials)
31
32 SOLUTION: euler024