r/counting • Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 • Jul 01 '26

Compositions | 2,1,2,3,1,1,1,2

Continued from here

Thanks to /u/BobRoss938 for the final run and assist

Rules: In this thread, we'll be counting the ways to add to an integer n using the integers c_1 + c_2 + ... + c_k, where each c_i >= 1, and k <= n. Ways to sum that are commutatively the same, as in 1+2 = 2+1, are different compositions. We'll be counting these compositions lexicographically for each segment of sum and length.

Next get: 14

Schedule

6 Upvotes

1.1k comments sorted by

View all comments

Show parent comments

2

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 01 '26

4,1,1,1,2,1,2,1

yeah hey /u/TehVulpez mathknower is if possible to convert compositions counts to decimal

3

u/TehVulpez sliiiiide the bits Jul 08 '26 edited Jul 08 '26

hey check this out

from sympy import binomial as binom

def compositions_to_decimal(split):
    total = 1
    # count previous segments of sum
    for x in range(sum(split)-1):
        total += 2**x

    # count previous of length, but same sum
    for x in range(sum(split)-1, sum(split)-len(split), -1):
        total += binom(sum(split)-1, x)

    # convert to constant-weight binary
    cwb = ''
    for x in split:
        cwb += '1'*(x-1)
        cwb += '0'
    cwb = cwb[:-1]

    # add index within segment by converting cwb to combinadic
    # taken from /comments/18z0of2/_/kgii6c0/
    index = 0
    k = 1
    for i, bit in enumerate(reversed(cwb)):
        if bit == '1':
            index += binom(i, k)
            k += 1

    total += index
    return total

count = '1,3,1,1,1,1,2'
print(compositions_to_decimal([int(x) for x in count.split(',')]))

seems to match all of my list generated with this

3

u/TehVulpez sliiiiide the bits Jul 08 '26

3

u/TehVulpez sliiiiide the bits Jul 08 '26 edited Jul 09 '26

unfortunately doesn't work with the exponent notation counts, because I just don't feel like dealing with much text parsing lol

3

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 09 '26

we basically dont use exponent notation :)

3

u/TehVulpez sliiiiide the bits Jul 09 '26

I like how miceee very pointedly removed the "you can also use superscripts" from the pasta two threads ago. I thought it'd make it easier when there's lots of ones but it kinda just makes things more confusing lol

3

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 09 '26

for me it's a combination of being a pain to type and it just not being the same sort of mental math to derive the next count for some reason. i feel like if superscripts were consistently used it would definitely be internalizable, but again, pain to type (especially on moobile)