*****************************************************************************
*       www.FindStat.org - The Combinatorial Statistic Finder               *
*                                                                           *
*       Copyright (C) 2019 The FindStatCrew <info@findstat.org>             *
*                                                                           *
*    This information is distributed in the hope that it will be useful,    *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   *
*****************************************************************************

-----------------------------------------------------------------------------
Statistic identifier: St001915

-----------------------------------------------------------------------------
Collection: Binary words

-----------------------------------------------------------------------------
Description: The size of the component corresponding to a necklace in Bulgarian solitaire.

A move in Bulgarian solitaire consists of removing the first column of the Ferrers diagram and inserting it as a new row.

The connected components of the corresponding discrete dynamical system are indexed by necklaces in a natural way.

-----------------------------------------------------------------------------
References: [1]   (service unreachable) [[MathSciNet:0656129]]
[2] Society, pages 483–486, 1982 

-----------------------------------------------------------------------------
Code:
def move(la):
    return Partition(sorted([p-1 for p in la] + [len(la)], reverse=True))

def necklace_to_partition(w):
    m = len(w)
    la = [m - i + b for i, b in enumerate(w, 1)]
    return Partition(la)

@cached_function
def components(n):
    B = DiscreteDynamicalSystem(Partitions(n), move)
    C = {frozenset(c): set(c) for c in B.cycles()}
    E = set(B).difference(*C.values())
    while E:
        e = E.pop()
        if not any(e in c for c in C.values()):
            o, k = B.orbit(e, True)
            c = frozenset(o[k:])
            r = o[:k]
            C[c].update(r)
            E.difference_update(r)
    return C

def component(la):
    la = Partition(la)
    n = la.size()
    B = DiscreteDynamicalSystem(Partitions(n), move)
    o, k = B.orbit(la, preperiod=True)
    return components(n)[frozenset(o[k:])]

def statistic(w):
    return len(component(necklace_to_partition(w)))

-----------------------------------------------------------------------------
Statistic values:

0         => 1
1         => 1
00        => 1
01        => 2
10        => 2
11        => 3
000       => 3
001       => 5
010       => 5
011       => 7
100       => 5
101       => 7
110       => 7
111       => 11
0000      => 11
0001      => 15
0010      => 15
0011      => 15
0100      => 15
0101      => 7
0110      => 15
0111      => 30
1000      => 15
1001      => 15
1010      => 7
1011      => 30
1100      => 15
1101      => 30
1110      => 30
1111      => 42
00000     => 42
00001     => 56
00010     => 56
00011     => 45
00100     => 56
00101     => 32
00110     => 45
00111     => 67
01000     => 56
01001     => 32
01010     => 32
01011     => 34
01100     => 45
01101     => 34
01110     => 67
01111     => 135
10000     => 56
10001     => 45
10010     => 32
10011     => 67
10100     => 32
10101     => 34
10110     => 34
10111     => 135
11000     => 45
11001     => 67
11010     => 34
11011     => 135
11100     => 67
11101     => 135
11110     => 135
11111     => 176
000000    => 176
000001    => 231
000010    => 231
000011    => 185
000100    => 231
000101    => 87
000110    => 185
000111    => 214
001000    => 231
001001    => 25
001010    => 87
001011    => 80
001100    => 185
001101    => 65
001110    => 214
001111    => 322
010000    => 231
010001    => 87
010010    => 25
010011    => 65
010100    => 87
010101    => 26
010110    => 80
010111    => 133
011000    => 185
011001    => 80
011010    => 65
011011    => 35
011100    => 214
011101    => 133
011110    => 322
011111    => 627
100000    => 231
100001    => 185
100010    => 87
100011    => 214
100100    => 25
100101    => 80
100110    => 65
100111    => 322
101000    => 87
101001    => 65
101010    => 26
101011    => 133
101100    => 80
101101    => 35
101110    => 133
101111    => 627
110000    => 185
110001    => 214
110010    => 80
110011    => 322
110100    => 65
110101    => 133
110110    => 35
110111    => 627
111000    => 214
111001    => 322
111010    => 133
111011    => 627
111100    => 322
111101    => 627
111110    => 627
111111    => 792
0000000   => 792
0000001   => 1002
0000010   => 1002
0000011   => 811
0000100   => 1002
0000101   => 294
0000110   => 811
0000111   => 777
0001000   => 1002
0001001   => 150
0001010   => 294
0001011   => 336
0001100   => 811
0001101   => 189
0001110   => 777
0001111   => 1114
0010000   => 1002
0010001   => 150
0010010   => 150
0010011   => 125
0010100   => 294
0010101   => 148
0010110   => 336
0010111   => 286
0011000   => 811
0011001   => 125
0011010   => 189
0011011   => 145
0011100   => 777
0011101   => 255
0011110   => 1114
0011111   => 1637
0100000   => 1002
0100001   => 294
0100010   => 150
0100011   => 189
0100100   => 150
0100101   => 148
0100110   => 125
0100111   => 255
0101000   => 294
0101001   => 148
0101010   => 148
0101011   => 158
0101100   => 336
0101101   => 158
0101110   => 286
0101111   => 544
0110000   => 811
0110001   => 336
0110010   => 125
0110011   => 145
0110100   => 189
0110101   => 158
0110110   => 145
0110111   => 255
0111000   => 777
0111001   => 286
0111010   => 255
0111011   => 255
0111100   => 1114
0111101   => 544
0111110   => 1637
0111111   => 3010
1000000   => 1002
1000001   => 811
1000010   => 294
1000011   => 777
1000100   => 150
1000101   => 336
1000110   => 189
1000111   => 1114
1001000   => 150
1001001   => 125
1001010   => 148
1001011   => 286
1001100   => 125
1001101   => 145
1001110   => 255
1001111   => 1637
1010000   => 294
1010001   => 189
1010010   => 148
1010011   => 255
1010100   => 148
1010101   => 158
1010110   => 158
1010111   => 544
1011000   => 336
1011001   => 145
1011010   => 158
1011011   => 255
1011100   => 286
1011101   => 255
1011110   => 544
1011111   => 3010
1100000   => 811
1100001   => 777
1100010   => 336
1100011   => 1114
1100100   => 125
1100101   => 286
1100110   => 145
1100111   => 1637
1101000   => 189
1101001   => 255
1101010   => 158
1101011   => 544
1101100   => 145
1101101   => 255
1101110   => 255
1101111   => 3010
1110000   => 777
1110001   => 1114
1110010   => 286
1110011   => 1637
1110100   => 255
1110101   => 544
1110110   => 255
1110111   => 3010
1111000   => 1114
1111001   => 1637
1111010   => 544
1111011   => 3010
1111100   => 1637
1111101   => 3010
1111110   => 3010
1111111   => 3718
00000000  => 3718
00000001  => 4565
00000010  => 4565
00000011  => 3727
00000100  => 4565
00000101  => 1152
00000110  => 3727
00000111  => 3880
00001000  => 4565
00001001  => 500
00001010  => 1152
00001011  => 815
00001100  => 3727
00001101  => 747
00001110  => 3880
00001111  => 4420
00010000  => 4565
00010001  => 225
00010010  => 500
00010011  => 375
00010100  => 1152
00010101  => 420
00010110  => 815
00010111  => 1076
00011000  => 3727
00011001  => 360
00011010  => 747
00011011  => 414
00011100  => 3880
00011101  => 802
00011110  => 4420
00011111  => 5972
00100000  => 4565
00100001  => 500
00100010  => 225
00100011  => 360
00100100  => 500
00100101  => 245
00100110  => 375
00100111  => 470
00101000  => 1152
00101001  => 245
00101010  => 420
00101011  => 309
00101100  => 815
00101101  => 316
00101110  => 1076
00101111  => 1082
00110000  => 3727
00110001  => 375
00110010  => 360
00110011  => 150
00110100  => 747
00110101  => 295
00110110  => 414
00110111  => 525
00111000  => 3880
00111001  => 470
00111010  => 802
00111011  => 524
00111100  => 4420
00111101  => 1158
00111110  => 5972
00111111  => 8463
01000000  => 4565
01000001  => 1152
01000010  => 500
01000011  => 747
01000100  => 225
01000101  => 420
01000110  => 360
01000111  => 802
01001000  => 500
01001001  => 245
01001010  => 245
01001011  => 316
01001100  => 375
01001101  => 295
01001110  => 470
01001111  => 1158
01010000  => 1152
01010001  => 420
01010010  => 245
01010011  => 295
01010100  => 420
01010101  => 97
01010110  => 309
01010111  => 593
01011000  => 815
01011001  => 309
01011010  => 316
01011011  => 289
01011100  => 1076
01011101  => 593
01011110  => 1082
01011111  => 2414
01100000  => 3727
01100001  => 815
01100010  => 375
01100011  => 414
01100100  => 360
01100101  => 309
01100110  => 150
01100111  => 524
01101000  => 747
01101001  => 316
01101010  => 295
01101011  => 289
01101100  => 414
01101101  => 289
01101110  => 525
01101111  => 983
01110000  => 3880
01110001  => 1076
01110010  => 470
01110011  => 525
01110100  => 802
01110101  => 593
01110110  => 524
01110111  => 450
01111000  => 4420
01111001  => 1082
01111010  => 1158
01111011  => 983
01111100  => 5972
01111101  => 2414
01111110  => 8463
01111111  => 14883
10000000  => 4565
10000001  => 3727
10000010  => 1152
10000011  => 3880
10000100  => 500
10000101  => 815
10000110  => 747
10000111  => 4420
10001000  => 225
10001001  => 375
10001010  => 420
10001011  => 1076
10001100  => 360
10001101  => 414
10001110  => 802
10001111  => 5972
10010000  => 500
10010001  => 360
10010010  => 245
10010011  => 470
10010100  => 245
10010101  => 309
10010110  => 316
10010111  => 1082
10011000  => 375
10011001  => 150
10011010  => 295
10011011  => 525
10011100  => 470
10011101  => 524
10011110  => 1158
10011111  => 8463
10100000  => 1152
10100001  => 747
10100010  => 420
10100011  => 802
10100100  => 245
10100101  => 316
10100110  => 295
10100111  => 1158
10101000  => 420
10101001  => 295
10101010  => 97
10101011  => 593
10101100  => 309
10101101  => 289
10101110  => 593
10101111  => 2414
10110000  => 815
10110001  => 414
10110010  => 309
10110011  => 524
10110100  => 316
10110101  => 289
10110110  => 289
10110111  => 983
10111000  => 1076
10111001  => 525
10111010  => 593
10111011  => 450
10111100  => 1082
10111101  => 983
10111110  => 2414
10111111  => 14883
11000000  => 3727
11000001  => 3880
11000010  => 815
11000011  => 4420
11000100  => 375
11000101  => 1076
11000110  => 414
11000111  => 5972
11001000  => 360
11001001  => 470
11001010  => 309
11001011  => 1082
11001100  => 150
11001101  => 525
11001110  => 524
11001111  => 8463
11010000  => 747
11010001  => 802
11010010  => 316
11010011  => 1158
11010100  => 295
11010101  => 593
11010110  => 289
11010111  => 2414
11011000  => 414
11011001  => 524
11011010  => 289
11011011  => 983
11011100  => 525
11011101  => 450
11011110  => 983
11011111  => 14883
11100000  => 3880
11100001  => 4420
11100010  => 1076
11100011  => 5972
11100100  => 470
11100101  => 1082
11100110  => 525
11100111  => 8463
11101000  => 802
11101001  => 1158
11101010  => 593
11101011  => 2414
11101100  => 524
11101101  => 983
11101110  => 450
11101111  => 14883
11110000  => 4420
11110001  => 5972
11110010  => 1082
11110011  => 8463
11110100  => 1158
11110101  => 2414
11110110  => 983
11110111  => 14883
11111000  => 5972
11111001  => 8463
11111010  => 2414
11111011  => 14883
11111100  => 8463
11111101  => 14883
11111110  => 14883
11111111  => 17977
000000000 => 17977

-----------------------------------------------------------------------------
Created: Aug 16, 2023 at 08:53 by Martin Rubey

-----------------------------------------------------------------------------
Last Updated: Aug 16, 2023 at 08:53 by Martin Rubey