*****************************************************************************
*       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: St000443

-----------------------------------------------------------------------------
Collection: Dyck paths

-----------------------------------------------------------------------------
Description: The number of long tunnels of a Dyck path.

A long tunnel of a Dyck path is a longest sequence of consecutive usual tunnels, i.e., a longest sequence of tunnels where the end point of one is the starting point of the next. See [1] for the definition of tunnels.

-----------------------------------------------------------------------------
References: [1]   Elizalde, S. Fixed points and excedances in restricted permutations [[MathSciNet:2880679]] [[arXiv:math/0212221]]

-----------------------------------------------------------------------------
Code:
def merge_one(tns):
    tns = sorted(tns)
    for j in range(len(tns)):
        for i in range(j):
            t1 = tns[i]
            t2 = tns[j]
            if t1[1] == t2[0]:
                tns.pop(j)
                tns.pop(i)
                tns.append((t1[0],t2[1]))
                return tns
    return tns

def long_tunnels(D):
    tns = list(D.tunnels())
    n = len(tns) + 1
    while n > len(tns):
        n -= 1
        tns = merge_one(tns)
    return tns

def statistic(D):
    return len(long_tunnels(D))

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

[1,0]                     => 1
[1,0,1,0]                 => 1
[1,1,0,0]                 => 2
[1,0,1,0,1,0]             => 1
[1,0,1,1,0,0]             => 2
[1,1,0,0,1,0]             => 2
[1,1,0,1,0,0]             => 2
[1,1,1,0,0,0]             => 3
[1,0,1,0,1,0,1,0]         => 1
[1,0,1,0,1,1,0,0]         => 2
[1,0,1,1,0,0,1,0]         => 2
[1,0,1,1,0,1,0,0]         => 2
[1,0,1,1,1,0,0,0]         => 3
[1,1,0,0,1,0,1,0]         => 2
[1,1,0,0,1,1,0,0]         => 3
[1,1,0,1,0,0,1,0]         => 2
[1,1,0,1,0,1,0,0]         => 2
[1,1,0,1,1,0,0,0]         => 3
[1,1,1,0,0,0,1,0]         => 3
[1,1,1,0,0,1,0,0]         => 3
[1,1,1,0,1,0,0,0]         => 3
[1,1,1,1,0,0,0,0]         => 4
[1,0,1,0,1,0,1,0,1,0]     => 1
[1,0,1,0,1,0,1,1,0,0]     => 2
[1,0,1,0,1,1,0,0,1,0]     => 2
[1,0,1,0,1,1,0,1,0,0]     => 2
[1,0,1,0,1,1,1,0,0,0]     => 3
[1,0,1,1,0,0,1,0,1,0]     => 2
[1,0,1,1,0,0,1,1,0,0]     => 3
[1,0,1,1,0,1,0,0,1,0]     => 2
[1,0,1,1,0,1,0,1,0,0]     => 2
[1,0,1,1,0,1,1,0,0,0]     => 3
[1,0,1,1,1,0,0,0,1,0]     => 3
[1,0,1,1,1,0,0,1,0,0]     => 3
[1,0,1,1,1,0,1,0,0,0]     => 3
[1,0,1,1,1,1,0,0,0,0]     => 4
[1,1,0,0,1,0,1,0,1,0]     => 2
[1,1,0,0,1,0,1,1,0,0]     => 3
[1,1,0,0,1,1,0,0,1,0]     => 3
[1,1,0,0,1,1,0,1,0,0]     => 3
[1,1,0,0,1,1,1,0,0,0]     => 4
[1,1,0,1,0,0,1,0,1,0]     => 2
[1,1,0,1,0,0,1,1,0,0]     => 3
[1,1,0,1,0,1,0,0,1,0]     => 2
[1,1,0,1,0,1,0,1,0,0]     => 2
[1,1,0,1,0,1,1,0,0,0]     => 3
[1,1,0,1,1,0,0,0,1,0]     => 3
[1,1,0,1,1,0,0,1,0,0]     => 3
[1,1,0,1,1,0,1,0,0,0]     => 3
[1,1,0,1,1,1,0,0,0,0]     => 4
[1,1,1,0,0,0,1,0,1,0]     => 3
[1,1,1,0,0,0,1,1,0,0]     => 4
[1,1,1,0,0,1,0,0,1,0]     => 3
[1,1,1,0,0,1,0,1,0,0]     => 3
[1,1,1,0,0,1,1,0,0,0]     => 4
[1,1,1,0,1,0,0,0,1,0]     => 3
[1,1,1,0,1,0,0,1,0,0]     => 3
[1,1,1,0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4
[1,1,1,0,1,0,0,1,0,0,1,0] => 3
[1,1,1,0,1,0,0,1,0,1,0,0] => 3
[1,1,1,0,1,0,0,1,1,0,0,0] => 4
[1,1,1,0,1,0,1,0,0,0,1,0] => 3
[1,1,1,0,1,0,1,0,0,1,0,0] => 3
[1,1,1,0,1,0,1,0,1,0,0,0] => 3
[1,1,1,0,1,0,1,1,0,0,0,0] => 4
[1,1,1,0,1,1,0,0,0,0,1,0] => 4
[1,1,1,0,1,1,0,0,0,1,0,0] => 4
[1,1,1,0,1,1,0,0,1,0,0,0] => 4
[1,1,1,0,1,1,0,1,0,0,0,0] => 4
[1,1,1,0,1,1,1,0,0,0,0,0] => 5
[1,1,1,1,0,0,0,0,1,0,1,0] => 4
[1,1,1,1,0,0,0,0,1,1,0,0] => 5
[1,1,1,1,0,0,0,1,0,0,1,0] => 4
[1,1,1,1,0,0,0,1,0,1,0,0] => 4
[1,1,1,1,0,0,0,1,1,0,0,0] => 5
[1,1,1,1,0,0,1,0,0,0,1,0] => 4
[1,1,1,1,0,0,1,0,0,1,0,0] => 4
[1,1,1,1,0,0,1,0,1,0,0,0] => 4
[1,1,1,1,0,0,1,1,0,0,0,0] => 5
[1,1,1,1,0,1,0,0,0,0,1,0] => 4
[1,1,1,1,0,1,0,0,0,1,0,0] => 4
[1,1,1,1,0,1,0,0,1,0,0,0] => 4
[1,1,1,1,0,1,0,1,0,0,0,0] => 4
[1,1,1,1,0,1,1,0,0,0,0,0] => 5
[1,1,1,1,1,0,0,0,0,0,1,0] => 5
[1,1,1,1,1,0,0,0,0,1,0,0] => 5
[1,1,1,1,1,0,0,0,1,0,0,0] => 5
[1,1,1,1,1,0,0,1,0,0,0,0] => 5
[1,1,1,1,1,0,1,0,0,0,0,0] => 5
[1,1,1,1,1,1,0,0,0,0,0,0] => 6

-----------------------------------------------------------------------------
Created: Mar 07, 2016 at 20:02 by Christian Stump

-----------------------------------------------------------------------------
Last Updated: Jan 13, 2021 at 18:12 by Martin Rubey