Skip to content

MotzkinPaths ​

A name from the enumeratio catalogue with no kernel of its own yet; this page carries its crosswalk only.

Catalogued in the enumeratio database, with crosswalk rows in oeis; not yet written up here.

✓ checked against that system · ! checked, with disagreements (hover a chip)OEISA001006✓A086246✓A168049✓
MotzkinPaths(...)Catalogued in the enumeratio database, with crosswalk rows in oeis; not yet written up here.
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<motzkin_path>combinatoricsalways

Domain: Combinatorics

Definition

Epsil, as the implementation runs it.

count(_n)

0 if 0 > (_n - _n % 2) / 2 else _tables[_n * ((_n - _n % 2) / 2 + 1) + 0 + 1]

unrank(_n, _r)

Drop(Fold(Function(us if us[3] == 0 else Apply(
                                                (uc0: integer) => Join(
                                                                        [
                                                                          us[1] -
                                                                          0,
                                                                          us[2] +
                                                                          1,
                                                                          us[3] -
                                                                          1,
                                                                          1,
                                                                        ],
                                                                        Drop(us, 4),
                                                                        [1],
                                                                      ) if us[1] <
                                                                          uc0 else Apply(
                                                                                       (uc1: integer) => Join([
                                                                                                                us[1] - uc0,
                                                                                                                us[2] + 0,
                                                                                                                us[3] - 1,
                                                                                                                1,
                                                                                                              ], Drop(us, 4), [0]) if us[1] <
                                                                                                                                     uc0 + uc1 else Join([us[1] -
                                                                                                                                                 (uc0 + uc1), us[2] - 1, us[3] - 1, 1], Drop(us, 4), [-1]),
                                                                                       (0 if us[2] + 0 >
                                                                                             (_n -
                                                                                              _n % 2) /
                                                                                             2 else _tables[(us[3] - 1) *
                                                                                                           ((_n -
                                                                                                             _n % 2) /
                                                                                                            2 +
                                                                                                            1) +
                                                                                                           us[2] + 0 +
                                                                                                           1]) if 1 <= us[3] &&
                                                                                                                 us[2] + 0 >=
                                                                                                                 0 else 0,
                                                                                     ),
                                                (0 if us[2] + 1 > (_n - _n % 2) /
                                                                  2 else _tables[(us[3] - 1) *
                                                                                ((_n -
                                                                                  _n % 2) /
                                                                                 2 +
                                                                                 1) +
                                                                                us[2] + 1 +
                                                                                1]) if 1 <= us[3] &&
                                                                                      us[2] + 1 >=
                                                                                      0 else 0,
                                              ), us, ui), [_r, 0, _n, 1], Range(1, _n, 1)), 4)

rank(_n, _x)

Fold(Function(Apply(
                     (rc0: integer) => [rs[1] + 0, rs[2] + 1, rs[3] - 1, 1] if rx ==
                                                                               1 else Apply(
                                                                                            (rc1: integer) => [
                                                                                                                rs[1] + rc0,
                                                                                                                rs[2] + 0,
                                                                                                                rs[3] - 1,
                                                                                                                1,
                                                                                                              ] if rx == 0 else [rs[1] +
                                                                                                                                rc0 + rc1, rs[2] - 1, rs[3] - 1, 1],
                                                                                            (0 if rs[2] + 0 >
                                                                                                  (_n -
                                                                                                   _n % 2) /
                                                                                                  2 else _tables[(rs[3] - 1) *
                                                                                                                ((_n -
                                                                                                                  _n % 2) /
                                                                                                                 2 +
                                                                                                                 1) +
                                                                                                                rs[2] + 0 +
                                                                                                                1]) if 1 <= rs[3] &&
                                                                                                                      rs[2] + 0 >=
                                                                                                                      0 else 0,
                                                                                          ),
                     (0 if rs[2] + 1 > (_n - _n % 2) / 2 else _tables[(rs[3] - 1) *
                                                                      ((_n - _n %
                                                                             2) /
                                                                       2 + 1) + rs[2] +
                                                                         1 + 1]) if 1 <= rs[3] &&
                                                                                   rs[2] + 1 >=
                                                                                   0 else 0,
                   ), rs, rx), [0, 0, _n, 1], _x)[1]

valid(_n, _x)

Apply(
       (ve: list<integer>) => ve[1] == 0 && ve[2] == _n,
       Fold(
             Function(vs if vs[1] < 0 else [
                                             vs[1] + 1,
                                             vs[2] + 1,
                                             Max(vs[3], vs[1] + 1),
                                           ] if vx == 1 else [
                                                              vs[1] + 0,
                                                              vs[2] + 1,
                                                              Max(
                                                                   vs[3],
                                                                   vs[1] + 0,
                                                                 ),
                                                            ] if vx == 0 else [
                                                                               vs[1] -
                                                                               1,
                                                                               vs[2] +
                                                                               1,
                                                                               Max(vs[3], vs[1] - 1),
                                                                             ] if vx == -1 else [-1, 0, 0], vs, vx),
             [0, 0, 0],
             _x,
           ),
     )

tables(_n)

Fold(
      Function(
                Join(
                      t_t,
                      Fold(
                            Function(
                                      ReplaceAt(
                                                 t_row,
                                                 t_c + 1,
                                                 0 if t_s < t_c else (t_t[(t_s -
                                                                           1) *
                                                                          ((_n -
                                                                            _n %
                                                                            2) /
                                                                           2 + 1) + t_c +
                                                                             1 +
                                                                          1] if t_c +
                                                                               1 <=
                                                                               (_n -
                                                                                _n % 2) /
                                                                               2 else 0) +
                                                                     t_t[(t_s -
                                                                          1) * ((_n -
                                                                                _n % 2) /
                                                                               2 +
                                                                               1) +
                                                                         t_c + 0 +
                                                                         1] +
                                                                     (t_t[(t_s -
                                                                           1) *
                                                                          ((_n -
                                                                            _n %
                                                                            2) /
                                                                           2 + 1) +
                                                                          (t_c -
                                                                           1) + 1] if t_c -
                                                                               1 >=
                                                                               0 else 0),
                                               ),
                                      t_row,
                                      t_c,
                                    ),
                            Map(
                                 Function(0, t_z),
                                 Range(0, (_n - _n % 2) / 2 + 1 - 1, 1),
                               ),
                            Range(0, (_n - _n % 2) / 2 + 1 - 1, 1),
                          ),
                    ),
                t_t,
                t_s,
              ),
      Fold(
            Function(
                      ReplaceAt(t_row, t_c + 1, 1 if t_c == 0 else 0),
                      t_row,
                      t_c,
                    ),
            Map(Function(0, t_z), Range(0, (_n - _n % 2) / 2 + 1 - 1, 1)),
            Range(0, (_n - _n % 2) / 2 + 1 - 1, 1),
          ),
      Range(1, _n + 1 - 1, 1),
    )

Enumeration

About
CrosswalkOEIS ×3