aboutsummaryrefslogtreecommitdiff
path: root/challenge-054/jo-37/perl/ch-1.pl
blob: a3d48e406f8b0b3c0b807282c93d2dd3f350c5bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl

use v5.16;
use warnings;
use Math::Prime::Util 'numtoperm';

die <<EOS if @ARGV != 2;
usage: $0 N K

N
    permute numbers from 1 to N

K
    print k-th permutation of the numbers (one-based)

EOS

say "@{[map $_ + 1, numtoperm $ARGV[0], $ARGV[1] - 1]}";