#!/usr/bin/perl
use strict;
no strict 'refs';
use warnings;
use 5.36.0;
die "Usage: $0 <T: total elements> <S: pass length> <n: number of twos>" if $#ARGV < 2;
our ($T, $S, $n) = (int $ARGV[0], int $ARGV[1], int $ARGV[2]);
for (qw/T S n/) {
die "$$_ not a positive integer" if !($$_ > 0);
}
die "Not T>S" if ($S > $T);
die "Not n<S" if ($n > $S);
die "Not S-n<T" if ($S-$n > $T);
die "Not 2n<S" if (2*$n > $S);
my $Z=$S-$n;
my $k=2*$n;
# T! / (T-Z)! * S! / [(2^n) * n! * (S-k)! ]
say fact($T)/fact($T-$Z)*fact($S)/((2**$n)*fact($n)*fact($S-$k));
sub fact {
my $f = shift;
my $x = 1;
$x *= $_ foreach ($x++ .. $f);
return $x;
}
% ./wtf.pl
Usage: ./wtf.pl <T: total elements> <S: pass length> <n: number of twos> at ./p.pl line 7.
% ./wtf.pl 13 7 3
900900
It gives half of what you said, one of us is mistaken somewhere.