New answers tagged combinatorics
0
votes
Generate a Kirkman triple system
Python with numpy, 285 bytes
from numpy import*
def k(q):
t=q//6;a=array;r=range;R=a(r(q-1));X=R//t%2;h=a(r(3));g=1;p=lambda x:[(x+s)%q for s in r(q)]
while 1in g**R[1:]%q:g+=1
A=a([g**(i+...
1
vote
How many partitions do I have?
Desmos, 64 bytes
p(n)=1+∑_{i=1}^{n^n}0^{(n-∑_{j=1}^njmod(floor(ni/n^j),n))^2}
Try it on Desmos!
This is O(n^(n+1))
How it works
...
1
vote
1
vote
1
vote
Cryptic Multiplications
Charcoal, 36 bytes
FXχLθFEXχLη⪫⟦ικ×ικ⟧¶⊞υEκ⌕κλI№υ§υI⁺θη
Try it online! Link is to verbose version of code. Explanation:
FXχLθ
...
3
votes
Cryptic Multiplications
05AB1E, 20 bytes
€g°Ý`âIšεDPª»DSk»}ć¢
Port of @Steffan's Vyxal answer, but with less convenient builtins.
Try it online or verify (almost) all test cases (the last ...
1
vote
Cryptic Multiplications
Ruby, 108 bytes
->a,b{[*0..9].permutation.map{|c|"#{a}*#{b}==#{a*b}".tr('0-9',c*'')}.uniq.count{|c|/^0|\*0|=0/!~c&&eval(c)}}
Try it online!
4
votes
4
votes
Cryptic Multiplications
Vyxal s, 17 bytes
vL↵ʀΠƛ?"ƛΠJṄ:vḟ;≈
Try it Online!
This would flaglessly be 19 bytes. It can be shorter flagless, though:
...
3
votes
Cryptic Multiplications
Jelly, 20 18 17 bytes
Thanks to Steffan for a speed up! (‘×⁵ -> æċ⁵) and a byte that ended up saving elsewhere!
Save of 2 ...
7
votes
Cryptic Multiplications
K (ngn/k), 41 36 bytes
-5 bytes inspired by Jonathan Allan's answer.
{#*={.(=`k@x,*/x)_" "}'?+x,'!10*1+x}
Try it online! The last 4 cases are too slow to ...
3
votes
1
vote
How many partitions do I have?
Jelly, 5 bytes
ŻṗḋRċ
Try it online!
Non-builtin solution using Henry Bottomley's comment at the top of the OEIS page. Although this obviously doesn't beat the ...
0
votes
Calculate the partitions of N
Curry (PAKCS), 44 bytes
(1!)
_!0=[]
a!n=anyOf[a ..n]#n
a#n=a:a!(n-a)
Try it online!
1
vote
1
vote
How many partitions do I have?
Vyxal l, 1 byte
Ṅ
Try it Online!
Vyxal, 2 bytes
ṄL
Try it Online!
1
vote
Sum of combinations with repetition
Vyxal, 9 bytes
⁺¤fẋfṗUṠO
Try it Online!
The header in the link halves the input to make things faster. It will return the same result if you remove it, but it may ...
0
votes
Sum of combinations with repetition
Regex 🐇 (ECMAScriptRME / Perl / PCRE / Raku:P5), 14 bytes
^(xxx?|x{5})*$
Takes its input ...
0
votes
Calculate the partitions of N
05AB1E, 8 bytes
Å1.œO€{ê
Outputs as a list of lists, from n amount of 1s to [n], where each ...
1
vote
How many partitions do I have?
05AB1E, 3 bytes
Åœg
Try it online or verify all test cases.
Explanation:
...
1
vote
Restricted Integer Partitions
Vyxal, 5 bytes
ṄvL=∑
Try it Online!
Jelly, 5 bytes
ŒṗẈ=S
Try it online!
Dang it, ninja'd by Kevin because I took the time to ...
2
votes
Restricted Integer Partitions
05AB1E, 5 bytes
ÅœIùg
Try it online or verify all test cases.
Explanation:
...
3
votes
How many partitions do I have?
Regex 🐇 (RME / Perl / PCRE2 v10.35+ / Raku:P5), 13 bytes
^(\1x*|^x+)*$
Try it on replit....
1
vote
Restricted Integer Partitions
Regex 🐇 (Perl/PCRE+(?^=)RME), 32 28 bytes
^((?^=(\2?x))(\1|^x)x*)+,\2$
Try it on replit....
1
vote
Generate number set with conditions using n numbers
Python, 168 165 bytes
from itertools import*
def f(n,k,v):
c,r,i=combinations,range(n),0
while i:=i+1:
for t in c(c(r,k),i):
if not{*c(r,v)}-{*chain(*[c(s,v)for s in t])}:return t
Attempt This ...
2
votes
Generate number set with conditions using n numbers
JavaScript (ES10), 188 bytes
Another brute-force solution that is unlikely to solve the second test case before the heat death of the universe.
Results are 0-indexed.
...
2
votes
Generate number set with conditions using n numbers
Vyxal, 14 bytes
ɾḋṗṘµ⁰vḋÞfUL;t
Try it Online!
Basically a port of Jelly, aka extremely slow.
Explanation coming soon.
3
votes
Generate number set with conditions using n numbers
Jelly, 15 bytes
œcŒPṚœc€⁵ẎQLƲÞṪ
A full program that accepts alphabet size (n), block size (k), and subset size (v) and prints a minimum covering design.
Try it ...
Top 50 recent answers are included
Related Tags
combinatorics × 353code-golf × 293
math × 82
sequence × 67
permutations × 39
fastest-code × 31
number × 27
grid × 25
geometry × 22
code-challenge × 21
number-theory × 20
string × 18
set-partitions × 17
integer-partitions × 15
graph-theory × 14
tiling × 13
array × 13
arithmetic × 12
polyomino × 12
decision-problem × 11
random × 9
counting × 8
game × 7
ascii-art × 6
binary × 6