From 1062338b2befbbf0c22c9e88c59da787e456c2e1 Mon Sep 17 00:00:00 2001 From: Sidney Zhang Date: Tue, 23 Dec 2025 18:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(euler=5F24.py)=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AC=A7=E6=8B=89=E9=A1=B9=E7=9B=AE=E7=AC=AC?= =?UTF-8?q?24=E9=A2=98=E7=9A=84=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88=20?= =?UTF-8?q?=F0=9F=93=9D=20docs(euler=5F24.py)=EF=BC=9A=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E6=8F=8F=E8=BF=B0=E5=92=8C=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/0024/euler_24.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 solutions/0024/euler_24.py diff --git a/solutions/0024/euler_24.py b/solutions/0024/euler_24.py new file mode 100644 index 0000000..02640d0 --- /dev/null +++ b/solutions/0024/euler_24.py @@ -0,0 +1,29 @@ +""" +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? +""" + +from itertools import permutations + + +def ordered_permutations(n: int) -> list[int]: + digits = list(range(10)) + all_permutations = permutations(digits) + for _ in range(n - 1): + next(all_permutations) + return next(all_permutations) + + +def main(): + n = 1000000 + result = ordered_permutations(n) + print("".join(map(str, result))) + + +if __name__ == "__main__": + main()