From 7d24dab64701efb473721b5aedf6e199dec0b18f Mon Sep 17 00:00:00 2001 From: Nikos M Date: Thu, 29 Dec 2016 23:05:30 +0200 Subject: [PATCH] v.0.5.1 * add some restricted partitions support (eg into exactly K parts, OR with M maximum value) * method signature and name changes, ie .rewind(-1) instead of .forward(), .next(-1) instead of .prev(), .hasNext(-1) instead of .hasPrev() * extended options on object instantiation, eg type, parameters, oredring, etc.. * some optimisations, minor fixes * included: permutations, combinations (with repeats), subsets, partitions (with K parts OR M max value), tensors, tuples * orderings: lex, colex, revlex, revcolex, reflex, refcolex, random --- README.md | 138 ++++--- src/js/Abacus.js | 732 +++++++++++++++++++++------------- src/js/Abacus.min.js | 4 +- test/combinations.js | 6 +- test/combinations.txt | 34 +- test/combinations_repeats.js | 10 +- test/combinations_repeats.txt | 92 ++--- test/partitions.js | 108 ++++- test/partitions.txt | 112 +++++- test/permutations-bigint.txt | 78 ++-- test/permutations.js | 17 +- test/permutations.txt | 136 +++++-- test/subsets.js | 6 +- test/subsets.txt | 152 +++---- test/tensors.js | 6 +- test/tensors.txt | 14 +- test/tuples.js | 6 +- test/tuples.txt | 46 +-- 18 files changed, 1082 insertions(+), 615 deletions(-) diff --git a/README.md b/README.md index e7ac72a..75434f8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A combinatorics library for Node/XPCOM/JS, PHP, Python (php/python implementations in progress) -**version 0.5.0** +**version 0.5.1** (~ 28kB minified, ~ 9kB zipped) ![abacus combinatorial numbers](/abacus.jpg) @@ -51,7 +51,7 @@ A combinatorics library for Node/XPCOM/JS, PHP, Python **permutations** (see `test/permutations.js`) ```text -Abacus.Permutations (VERSION = 0.5.0) +Abacus.Permutations (VERSION = 0.5.1) --- o = Abacus.Permutation(4) o.total() @@ -67,173 +67,221 @@ o.rewind() [ [ 0, 1, 2, 3 ], 'index : 0', 'rank : 0', + 'unrank : 0,1,2,3', 'is_permutation : yes', 'is_identity : yes', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 1, 3, 2 ], 'index : 1', 'rank : 1', + 'unrank : 0,1,3,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 2, 1, 3 ], 'index : 2', 'rank : 2', + 'unrank : 0,2,1,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 2, 3, 1 ], 'index : 3', 'rank : 3', + 'unrank : 0,2,3,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 0, 3, 1, 2 ], 'index : 4', 'rank : 4', + 'unrank : 0,3,1,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 0, 3, 2, 1 ], 'index : 5', 'rank : 5', + 'unrank : 0,3,2,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 0, 2, 3 ], 'index : 6', 'rank : 6', + 'unrank : 1,0,2,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 0, 3, 2 ], 'index : 7', 'rank : 7', + 'unrank : 1,0,3,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 2, 0, 3 ], 'index : 8', 'rank : 8', + 'unrank : 1,2,0,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 1, 2, 3, 0 ], 'index : 9', 'rank : 9', + 'unrank : 1,2,3,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 1, 3, 0, 2 ], 'index : 10', 'rank : 10', + 'unrank : 1,3,0,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 1, 3, 2, 0 ], 'index : 11', 'rank : 11', + 'unrank : 1,3,2,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 0, 1, 3 ], 'index : 12', 'rank : 12', + 'unrank : 2,0,1,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 2, 0, 3, 1 ], 'index : 13', 'rank : 13', + 'unrank : 2,0,3,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 1, 0, 3 ], 'index : 14', 'rank : 14', + 'unrank : 2,1,0,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 2, 1, 3, 0 ], 'index : 15', 'rank : 15', + 'unrank : 2,1,3,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 3, 0, 1 ], 'index : 16', 'rank : 16', + 'unrank : 2,3,0,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 2, 3, 1, 0 ], 'index : 17', 'rank : 17', + 'unrank : 2,3,1,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 3, 0, 1, 2 ], 'index : 18', 'rank : 18', + 'unrank : 3,0,1,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 0, 2, 1 ], 'index : 19', 'rank : 19', + 'unrank : 3,0,2,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 1, 0, 2 ], 'index : 20', 'rank : 20', + 'unrank : 3,1,0,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 1, 2, 0 ], 'index : 21', 'rank : 21', + 'unrank : 3,1,2,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 3, 2, 0, 1 ], 'index : 22', 'rank : 22', + 'unrank : 3,2,0,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 3, 2, 1, 0 ], 'index : 23', 'rank : 23', + 'unrank : 3,2,1,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] backwards -o.forward() +o.rewind(-1) [ 3, 2, 1, 0 ] [ 3, 2, 0, 1 ] [ 3, 1, 2, 0 ] @@ -384,32 +432,32 @@ o.order("colex,reversed") [ 2, 3, 1, 0 ] [ 3, 2, 1, 0 ] o.order("random") -[ 1, 2, 0, 3 ] -[ 3, 1, 2, 0 ] -[ 0, 3, 2, 1 ] [ 1, 3, 0, 2 ] -[ 1, 3, 2, 0 ] -[ 2, 1, 3, 0 ] -[ 1, 0, 3, 2 ] -[ 2, 3, 1, 0 ] -[ 3, 0, 2, 1 ] -[ 2, 1, 0, 3 ] -[ 3, 2, 0, 1 ] -[ 3, 0, 1, 2 ] -[ 0, 3, 1, 2 ] [ 0, 2, 3, 1 ] -[ 1, 0, 2, 3 ] -[ 1, 2, 3, 0 ] -[ 2, 3, 0, 1 ] +[ 2, 3, 1, 0 ] [ 0, 2, 1, 3 ] [ 0, 1, 3, 2 ] +[ 1, 2, 0, 3 ] +[ 0, 3, 2, 1 ] +[ 2, 3, 0, 1 ] [ 0, 1, 2, 3 ] +[ 1, 0, 2, 3 ] +[ 3, 2, 1, 0 ] +[ 1, 0, 3, 2 ] +[ 3, 1, 0, 2 ] [ 2, 0, 1, 3 ] +[ 1, 2, 3, 0 ] +[ 1, 3, 2, 0 ] +[ 3, 0, 2, 1 ] [ 2, 0, 3, 1 ] -[ 3, 1, 0, 2 ] -[ 3, 2, 1, 0 ] -o.random() +[ 3, 1, 2, 0 ] +[ 2, 1, 3, 0 ] [ 0, 3, 1, 2 ] +[ 3, 2, 0, 1 ] +[ 3, 0, 1, 2 ] +[ 2, 1, 0, 3 ] +o.random() +[ 0, 1, 3, 2 ] o.order("colex").range(-5, -1) [ 1, 2, 0, 3 ] [ 2, 0, 1, 3 ] diff --git a/src/js/Abacus.js b/src/js/Abacus.js index 90a01f7..be13e61 100644 --- a/src/js/Abacus.js +++ b/src/js/Abacus.js @@ -2,7 +2,7 @@ * * Abacus * A combinatorics library for Node/XPCOM/JS, PHP, Python -* @version: 0.5.0 +* @version: 0.5.1 * https://github.com/foo123/Abacus **/ !function( root, name, factory ){ @@ -22,7 +22,7 @@ else if ( !(name in root) ) /* Browser/WebWorker/.. */ /* module factory */ function ModuleFactory__Abacus( undef ){ "use strict"; -var Abacus = {VERSION: "0.5.0"}, PROTO = 'prototype', CLASS = 'constructor' +var Abacus = {VERSION: "0.5.1"}, PROTO = 'prototype', CLASS = 'constructor' ,slice = Array.prototype.slice, HAS = Object[PROTO].hasOwnProperty, toString = Object[PROTO].toString ,trim_re = /^\s+|\s+$/g ,trim = String.prototype.trim @@ -116,22 +116,29 @@ function inversion( n, n0 ) return (n === +n)&&(n0 === +n0) ? (n0 - n) : Abacus.Arithmetic.sub( Abacus.Arithmetic.N( n0 ), n ); } } -function operate( F, F0, i0, i1, ik ) +function operate( F, F0, x, i0, i1, ik ) { - var Fv = F0, l, i, x; - if ( is_array(i0) ) + var Fv = F0, l, i; + if ( x && is_array(x) ) { - x = i0; l = x.length; - i0 = 0; i1 = l-1; ik = 1; - if ( 0 < l ) for(i=i0; i<=i1; i+=ik) Fv = F(Fv,x[i]); + l = x.length; + if ( null == i0 ) i0 = 0; + if ( null == i1 ) i1 = l-1; + if ( null == ik ) ik = 1; + if ( 0 < l ) + { + if ( 0 > ik ) for(i=i0; i>=i1; i+=ik) Fv = F(Fv,x[i],i); + else for(i=i0; i<=i1; i+=ik) Fv = F(Fv,x[i],i); + } } else { + //ik = i1; i1 = i0; i0 = x; ik = ik || 1; l = (i1-i0)/ik+1; if ( 0 < l ) { - if ( 0 > ik ) for(i=i0; i>=i1; i+=ik) Fv = F(Fv,i); - else for(i=i0; i<=i1; i+=ik) Fv = F(Fv,i); + if ( 0 > ik ) for(i=i0; i>=i1; i+=ik) Fv = F(Fv,i,i); + else for(i=i0; i<=i1; i+=ik) Fv = F(Fv,i,i); } } return Fv; @@ -208,7 +215,7 @@ function factorial( n, m ) // 2=>2 or 3=>6 else if ( Arithmetic.lt( n, 4 ) ) return Arithmetic.shl( n, Arithmetic.sub( n, 2 ) )/*n<<(n-2)*/; key = String(n); - if (null == factorial.fac[key] ) factorial.fac[key] = operate(mul, I, 2, n); + if (null == factorial.fac[key] ) factorial.fac[key] = operate(mul, I, null, 2, n); return factorial.fac[key]; } else if ( -1 === m ) @@ -217,7 +224,7 @@ function factorial( n, m ) Nk = NUM( n ); return operate(function(N, k){ return Nk === N ? N : sub(mul(N, k), N); - }, Nk, n, 1, -1); + }, Nk, null, n, 1, -1); } else if ( -2 === m ) { @@ -230,7 +237,7 @@ function factorial( n, m ) N[2] = -N[2]; if ( k > 1 && k <= n ) N[0] = mul(N[0], k); return k > n ? N[1] : N; - }, [I, O, 1], 0, n+1); + }, [I, O, 1], null, 0, n+1); } return factorial.sub[key]; } @@ -293,6 +300,8 @@ function partitions( n, k, m ) if ( null == partitions.tbl[tk] ) partitions.tbl[tk] = partitions( n-m, k-1, j ); p = add(p, partitions.tbl[tk]); } + tk = String(n)+','+String(k)+','+String(m); + if ( null == partitions.tbl[tk] ) partitions.tbl[tk] = p; return p; } partitions.tbl = {}; @@ -407,7 +416,7 @@ function mergesort( a/*, reverse*/ ) } return a; } -function shuffle( a, cyclic, copied ) +function shuffle( a, cyclic, copied, included ) { // http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Sattolo.27s_algorithm @@ -415,22 +424,36 @@ function shuffle( a, cyclic, copied ) N, perm, swap, ac, offset; ac = true === copied ? a.slice() : a; offset = true === cyclic ? 1 : 0; - N = ac.length; - while ( offset < N-- ) - { - perm = rndInt( 0, N-offset ); - swap = ac[ N ]; - ac[ N ] = ac[ perm ]; - ac[ perm ] = swap; + if ( included ) + { + N = included.length; + while ( offset < N-- ) + { + perm = rndInt( 0, N-offset ); + swap = ac[ included[N] ]; + ac[ included[N] ] = ac[ included[perm] ]; + ac[ included[perm] ] = swap; + } + } + else + { + N = ac.length; + while ( offset < N-- ) + { + perm = rndInt( 0, N-offset ); + swap = ac[ N ]; + ac[ N ] = ac[ perm ]; + ac[ perm ] = swap; + } } // in-place or copy return ac; } -function pick( a, k, repeated, sorted, non_destructive ) +function pick( a, k, repeated, sorted, backup ) { // http://stackoverflow.com/a/32035986/3591273 var rndInt = Abacus.Math.rndInt, - picked, backup, i, selected, value, n = a.length; + picked, i, selected, value, n = a.length; k = Abacus.Math.min( k, n ); sorted = true === sorted; @@ -444,9 +467,6 @@ function pick( a, k, repeated, sorted, non_destructive ) return picked; } - non_destructive = false !== non_destructive; - if ( non_destructive ) backup = new Array( k ); - // partially shuffle the array, and generate unbiased selection simultaneously // this is a variation on fisher-yates-knuth shuffle for (i=0; i=0; i--) // O(k) times @@ -758,17 +778,22 @@ function is_identity( perm ) for(var n=perm.length,i=0; i kfixed ) return false; + } + return true === strict ? nfixed === kfixed : true; } function has_cycle( perm, k, strict ) { @@ -992,71 +1017,115 @@ function next_tuple( item, N, dir ) } return null; } -function next_partition( item, N, dir ) +function next_partition( item, N, dir, K, M ) { if ( item ) { - var n = N, i, c, p1, p2, summa, rem, next = item.slice(); + var n = N, i, c, m, p1, p2, summa, rem, next = item.slice(); if ( 0 > dir ) { // C of item // compute prev partition - if ( next[0] > 1 ) + if ( K ) { - c = next.length; - // break into a partition with last part reduced by 1 from previous partition series - i = c-1; - while (i>=0 && 1 === next[i]) i--; - p1 = next[i]-1; - next = next.slice(0, i+1); - next[ i ] = p1; - for(summa=0,i=0,c=next.length; i 0 ) + m = M ? M : Math.ceil(n/K); + if ( next[0] > m ) { - p2 = rem; - if ( p2 > p1 ) - { - p2 = p1; - next.push(p2); - } - else - { - next.push(rem); - } - rem -= p2; + c = 1; summa = 0; + while (c= next[0]) { c++; } + next[c]++; + for(i=1; i m ) + { + c = next.length; + // break into a partition with last part reduced by 1 from previous partition series + i = c-1; + while (i>=0 && 1 === next[i]) i--; + p1 = next[i]-1; + next = next.slice(0, i+1); + next[ i ] = p1; + for(summa=0,i=0,c=next.length; i 0 ) + { + p2 = rem; + if ( p2 > p1 ) + { + p2 = p1; + next.push(p2); + } + else + { + next.push(rem); + } + rem -= p2; + } + } + // if partition is all ones (so first element is also one) it is the final partition + else + { + next = null; + } } // invC of item } else { // compute next partition - if ( next[0] < n ) + if ( K ) { - c = next.length; - i = c-1; if (i>0) i--; - while (i>0 && next[i] === next[i-1]) i--; - next[i]++; - next = next.slice( 0, i+1 ); - for(summa=0,i=0,c=next.length; i 0 ) + m = M ? M : n-K+1; + if ( next[0] < m ) { - next.push(1); - rem--; + c = K-1; + while (c>0 && 1 === next[c] ) { c--; } + i = c; + while(i>0 && next[i-1] === next[c] ) i--; + if ( i === c ) i = 0; + next[c]--; next[i]++; + } + // if partition is the number itself it is the final partition + else + { + next = null; } } - // if partition is the number itself it is the final partition - else - { - next = null; + else + { + m = M ? M : n; + if ( next[0] < m ) + { + c = next.length; + i = c-1; if (i>0) i--; + while (i>0 && next[i] === next[i-1]) i--; + next[i]++; + next = next.slice( 0, i+1 ); + for(summa=0,i=0,c=next.length; i 0 ) + { + next.push(1); + rem--; + } + } + // if partition is the number itself it is the final partition + else + { + next = null; + } } } return next; @@ -1097,6 +1166,20 @@ Abacus.ORDER = { }; // math/rnd utilities +Abacus.Util = { + + intersect: intersect + ,merge: merge + ,complement: complement + ,conjugation: conjugation + ,parity: parity + ,inversion: inversion + ,mergesort: mergesort + ,shuffle: shuffle + ,pick: pick + +}; + Abacus.Math = { O: 0 @@ -1143,6 +1226,12 @@ Abacus.Math = { ,num: function( a ) { return "number" === typeof a ? Abacus.Math.floor(a) : parseInt(a,10); } ,val: function( a ) { return Abacus.Math.floor(a.valueOf()); } +,sum: sum +,product: product +,pow2: pow2 +,exp: exp +,factorial: factorial +,partitions: partitions }; // support pluggable arithmetics, eg biginteger Arithmetic @@ -1191,6 +1280,8 @@ Abacus.Arithmetic = { }; +Abacus.Class = Class; + Abacus.BitArray = Class({ constructor: function BitArray(n) { @@ -1267,13 +1358,14 @@ Abacus.BitArray = Class({ // big-integers can be handled transparently throughout all the combinatorial algorithms CombinatorialIterator = Abacus.CombinatorialIterator = Class({ - constructor: function CombinatorialIterator( type, n, opts, order ) { + constructor: function CombinatorialIterator( n, $ ) { var self = this, klass = self[CLASS]; - self.type = String(type); self.n = n || 0; - self.options = opts || {}; - self._count = klass.count( self.n, self.type/*, self.options*/ ); - self.order( self.options.order || order || LEX ); // default order is lexicographic ("lex") + self.$ = $ = $ || {}; + $.type = String($.type || "combinatorial").toLowerCase(); + $.order = $.order || LEX; // default order is lexicographic ("lex") + $.count = klass.count( self.n, self.$ ); + self.order( $.order ); } ,__static__: { @@ -1300,34 +1392,32 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,initial: NotImplemented ,rank: NotImplemented ,unrank: NotImplemented - ,dual: function( item, index, n, type, order ) { + ,dual: function( item, index, n, $ ) { if ( null == item ) return null; // some C-P-T processes at play here - var klass = this, C = klass.C, P = klass.P, T = klass.T; - order = order|0; + var klass = this, order = $ && $.order ? $.order : 0, + C = klass.C, P = klass.P, T = klass.T; if ( RANDOM & order ) return REFLECTED & order ? P( item, n ) : item; else if ( COLEX & order ) return REFLECTED & order ? C( item, n ) : P( C( item, n ), n ); else/*if ( LEX & order )*/return REFLECTED & order ? P( item, n ) : item.slice( ); } - ,succ: function( dir, item, index, n, type, order, total ) { + ,succ: function( dir, item, index, n, $ ) { var klass = this, Arithmetic = Abacus.Arithmetic; return null == item ? null - : klass.unrank(Arithmetic.add(index, 0>dir?Arithmetic.J:Arithmetic.I), n, type, total) + : klass.unrank(Arithmetic.add(index, 0>dir?Arithmetic.J:Arithmetic.I), n, $) ; } - ,rand: function( n, type, total ) { - var klass = this, Arithmetic = Abacus.Arithmetic, - tot = null != total ? total : klass.count( n, type ); - return klass.unrank( Arithmetic.rnd(Arithmetic.O, Arithmetic.sub(tot, Arithmetic.I)), n, type, tot ); + ,rand: function( n, $ ) { + var klass = this, Arithmetic = Abacus.Arithmetic, total = $ && $.count ? $.count : klass.count(n, $); + return klass.unrank(Arithmetic.rnd(Arithmetic.O, Arithmetic.sub(total, Arithmetic.I)), n, $); } } - ,type: null - ,options: null ,n: 0 - ,_order: 0 - ,_count: 0 + ,m: null + ,i: null + ,$: null ,__index: null ,_index: null ,__item: null @@ -1338,11 +1428,10 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,dispose: function( ) { var self = this; - self.type = null; - self.options = null; self.n = null; - self._order = null; - self._count = 0; + self.m = null; + self.i = null; + self.$ = null; self.__index = null; self._index = null; self.__item = null; @@ -1360,14 +1449,16 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,_store: function( ) { var self = this; return [ - self._order + self.n + ,self.m + ,self.i + ,self.$.order ,self.__index ,self._index ,self.__item ,self._item ,self._prev ,self._next - ,self.n ]; } @@ -1375,20 +1466,22 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ var self = this; if ( state ) { - self._order = state[0]; - self.__index = state[1]; - self._index = state[2]; - self.__item = state[3]; - self._item = state[4]; - self._prev = state[5]; - self._next = state[6]; - self.n = state[7]; + self.n = state[0]; + self.m = state[1]; + self.i = state[2]; + self.$.order = state[3]; + self.__index = state[4]; + self._index = state[5]; + self.__item = state[6]; + self._item = state[7]; + self._prev = state[8]; + self._next = state[9]; } return self; } ,total: function( ) { - return this._count; + return this.$.count || 0; } ,order: function( order, reverse ) { @@ -1396,16 +1489,16 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ var self = this, Arithmetic = Abacus.Arithmetic, O = Arithmetic.O, I = Arithmetic.I, - klass = self[CLASS], T = klass.T, r, tot, tot_1, n, t, dir; + klass = self[CLASS], T = klass.T, r, tot, tot_1, n, $, dir; - reverse = false === reverse; + reverse = -1 === reverse; order = ORDER( order ); - tot = self._count; n = self.n; t = self.type; + n = self.n; $ = self.$; tot = $.count; tot_1 = Arithmetic.sub(tot, I); dir = REVERSED & order ? -1 : 1; // T dir = reverse ? -dir : dir; // T - self._order = order; + $.order = order; self.__index = self._index = O; self._item = self.__item = null; self._prev = false; self._next = false; @@ -1429,20 +1522,20 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ else self._traversed.reset( ); self._traversed.set( r=self.randomIndex( ) ); } - self.__item = klass.unrank( r, n, t, tot ); + self.__item = klass.unrank( r, n, $ ); if ( null != self.__item ) self.__index = r; } else if ( COLEX & order ) { - self.__item = klass.initial( -dir, n, t, order ); // T + self.__item = klass.initial( -dir, n, $ ); // T if ( null != self.__item ) self.__index = -1 === dir ? O : tot_1; } else /*if ( LEX & order )*/ { - self.__item = klass.initial( dir, n, t, order ); + self.__item = klass.initial( dir, n, $ ); if ( null != self.__item ) self.__index = -1 === dir ? tot_1 : O; } - self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, t, order ); + self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, $ ); self._index = reverse && !(RANDOM & order) ? tot_1 : O; self._prev = (RANDOM & order) || !reverse ? false : null != self.__item; self._next = reverse && !(RANDOM & order) ? false : null != self.__item; @@ -1454,8 +1547,8 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ var self = this, Arithmetic = Abacus.Arithmetic, O = Arithmetic.O, I = Arithmetic.I, J = Arithmetic.J, - klass = self[CLASS], T = klass.T, n = self.n, t = self.type, tot = self._count, - order = self._order, tot_1, dir = REVERSED & order ? -1 : 1; // T + klass = self[CLASS], T = klass.T, n = self.n, $ = self.$, tot = $.count, + order = $.order, tot_1, dir = REVERSED & order ? -1 : 1; // T index = Arithmetic.wrapR(Arithmetic.N( index ), tot); @@ -1467,11 +1560,11 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ self.__index = -1 === dir ? index : Arithmetic.sub(tot_1, index); self._index = index; self.__item = Arithmetic.equ(O, index) - ? klass.initial( -dir, n, t, order ) + ? klass.initial( -dir, n, $ ) : (Arithmetic.equ(tot_1, index) - ? klass.initial( dir, n, t, order ) - : klass.unrank( self.__index, n, t, tot )); - self._item = klass.dual( self.__item, self.__index, n, t, order ); + ? klass.initial( dir, n, $ ) + : klass.unrank( self.__index, n, $ )); + self._item = klass.dual( self.__item, self.__index, n, $ ); self._prev = null != self.__item; self._next = null != self.__item; } @@ -1480,11 +1573,11 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ self.__index = -1 === dir ? Arithmetic.sub(tot_1, index) : index; self._index = index; self.__item = Arithmetic.equ(O, index) - ? klass.initial( dir, n, t, order ) + ? klass.initial( dir, n, $ ) : (Arithmetic.equ(tot_1, index) - ? klass.initial( -dir, n, t, order ) - : klass.unrank( self.__index, n, t, tot )); - self._item = klass.dual( self.__item, self.__index, n, t, order ); + ? klass.initial( -dir, n, $ ) + : klass.unrank( self.__index, n, $ )); + self._item = klass.dual( self.__item, self.__index, n, $ ); self._prev = null != self.__item; self._next = null != self.__item; } @@ -1495,14 +1588,14 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,item: function( index, order ) { if ( !arguments.length ) return this._item; - var self = this, n = self.n, t = self.type, tot = self._count, tot_1, dir, indx, + var self = this, n = self.n, $ = self.$, tot = $.count, tot_1, dir, indx, klass = self[CLASS], T = klass.T, Arithmetic = Abacus.Arithmetic, - O = Arithmetic.O, I = Arithmetic.I, J = Arithmetic.J; - order = null != order ? ORDER( order ) : self._order; + O = Arithmetic.O, I = Arithmetic.I, J = Arithmetic.J, o, ret; + order = null != order ? ORDER( order ) : $.order; index = Arithmetic.wrapR(Arithmetic.N( index ), tot); - if ( (order === self._order) && Arithmetic.equ(index, self._index) ) return self._item; + if ( (order === $.order) && Arithmetic.equ(index, self._index) ) return self._item; if ( Arithmetic.inside(index, J, tot) ) { @@ -1511,29 +1604,38 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ if ( RANDOM & order ) { indx = self.randomIndex( ); - return klass.dual( - klass.unrank( indx, n, t, tot ) + o = $.order; $.order = order; + ret = klass.dual( + klass.unrank( indx, n, $ ) /*klass.rand( n, tot )*/ - , indx, n, t, order + , indx, n, $ ); + $.order = o; + return ret; } else if ( COLEX & order ) { indx = -1 === dir ? index : Arithmetic.sub(tot_1, index); - return klass.dual( Arithmetic.equ(O, index) - ? klass.initial( -dir, n, t, order ) + o = $.order; $.order = order; + ret = klass.dual( Arithmetic.equ(O, index) + ? klass.initial( -dir, n, $ ) : (Arithmetic.equ(tot_1, index) - ? klass.initial( dir, n, t, order ) - : klass.unrank( indx, n, t, tot )), indx, n, t, order ); + ? klass.initial( dir, n, $ ) + : klass.unrank( indx, n, $ )), indx, n, $ ); + $.order = o; + return ret; } else /*if ( LEX & order )*/ { indx = -1 === dir ? Arithmetic.sub(tot_1, index) : index; - return klass.dual( Arithmetic.equ(O, index) - ? klass.initial( dir, n, t, order ) + o = $.order; $.order = order; + ret = klass.dual( Arithmetic.equ(O, index) + ? klass.initial( dir, n, $ ) : (Arithmetic.equ(tot_1, index) - ? klass.initial( -dir, n, t, order ) - : klass.unrank( indx, n, t, tot )), indx, n, t, order ); + ? klass.initial( -dir, n, $ ) + : klass.unrank( indx, n, $ )), indx, n, $ ); + $.order = o; + return ret; } } return null; @@ -1542,7 +1644,7 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,randomIndex: function( m, M ) { var self = this, Arithmetic = Abacus.Arithmetic, N = Arithmetic.N, O = Arithmetic.O, I = Arithmetic.I, - tot = self._count, argslen = arguments.length; + tot = self.$.count, argslen = arguments.length; if ( 0 === argslen ) { m = O; @@ -1562,20 +1664,54 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ } ,random: function( ) { - var self = this, klass = self[CLASS]; - return klass.dual( klass.rand( self.n, self.type, self._count ), null, self.n, self.type, RANDOM|self._order ); + var self = this, klass = self[CLASS], ret, o = self.$.order; + self.$.order |= RANDOM; + ret = klass.rand( self.n, self.$ ); + self.$.order = o; + ret = klass.dual( ret, null, self.n, self.$ ); + return ret; + } + + ,rewind: function( dir ) { + var self = this; + return self.order( self.$.order, -1 === dir ? -1 : 1 ); } - ,rewind: function( ) { - return this.order( this._order, true ); + ,hasNext: function( dir ) { + var self = this; + return -1 === dir ? (RANDOM & self.$.order ? false : self._prev) : self._next; } // some C-P-T processes at play here as well, see below - ,next: function( ) { + ,next: function( dir ) { var self = this, Arithmetic = Abacus.Arithmetic, O = Arithmetic.O, I = Arithmetic.I, J = Arithmetic.J, - order = self._order, traversed, r, dir, klass = self[CLASS], T = klass.T, - current = self._item, n = self.n, t = self.type, tot = self._count, tot_1, rs; + traversed, r, dir, klass = self[CLASS], T = klass.T, + current = self._item, n = self.n, $ = self.$, + order = $.order, tot = $.count, tot_1, rs; + + if ( -1 === dir ) + { + // random and stochastic order has no prev + if ( RANDOM & order ) return null; + + dir = REVERSED & order ? -1 : 1; // T + // compute prev, using successor methods / loopless algorithms, WITHOUT using big integer arithemtic + if ( COLEX & order ) + { + self.__item = klass.succ( dir, self.__item, self.__index, n, $ ); + if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 > dir ? J : I); + } + else /*if ( LEX & order )*/ + { + self.__item = klass.succ( -dir, self.__item, self.__index, n, $ ); + if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 < dir ? J : I); + } + self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, $ ); + self._prev = null != self.__item; + if ( self._prev ) self._index = Arithmetic.sub(self._index, I); + return current; + } if ( RANDOM & order ) { @@ -1586,7 +1722,7 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ if ( !traversed ) { r = self.randomIndex( ); - self.__item = klass.unrank( r, n, t, tot ); + self.__item = klass.unrank( r, n, $ ); if ( null != self.__item ) self.__index = r; } else @@ -1596,7 +1732,7 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ rs = Abacus.Math.rnd( ) > 0.5 ? J : I; while ( traversed.isset( r ) ) r = Arithmetic.wrap( Arithmetic.add(r, rs), O, tot_1 ); traversed.set( r ); - self.__item = klass.unrank( r, n, t, tot ); + self.__item = klass.unrank( r, n, $ ); if ( null != self.__item ) self.__index = r; } } @@ -1616,66 +1752,27 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ // compute next, using successor methods / loopless algorithms, WITHOUT using big integer arithemtic if ( COLEX & order ) { - self.__item = klass.succ( -dir, self.__item, self.__index, n, t, order, tot ); + self.__item = klass.succ( -dir, self.__item, self.__index, n, $ ); if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 < dir ? J : I); } else /*if ( LEX & order )*/ { - self.__item = klass.succ( dir, self.__item, self.__index, n, t, order, tot ); + self.__item = klass.succ( dir, self.__item, self.__index, n, $ ); if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 > dir ? J : I); } } - self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, t, order ); + self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, $ ); self._next = null != self.__item; if ( self._next ) self._index = Arithmetic.add(self._index, I); return current; } - ,hasNext: function( ) { - return this._next; - } - - ,forward: function( ) { - return this.order( this._order, false ); - } - - // some C-P-T processes at play here as well, see below - ,prev: function( ) { - var self = this, Arithmetic = Abacus.Arithmetic, I = Arithmetic.I, J = Arithmetic.J, - order = self._order, dir, klass = self[CLASS], T = klass.T, - current = self._item, n = self.n, t = self.type, tot = self._count; - - // random and stochastic order has no prev - if ( RANDOM & order ) return null; - - dir = REVERSED & order ? -1 : 1; // T - // compute prev, using successor methods / loopless algorithms, WITHOUT using big integer arithemtic - if ( COLEX & order ) - { - self.__item = klass.succ( dir, self.__item, self.__index, n, t, order, tot ); - if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 > dir ? J : I); - } - else /*if ( LEX & order )*/ - { - self.__item = klass.succ( -dir, self.__item, self.__index, n, t, order, tot ); - if ( null != self.__item ) self.__index = Arithmetic.add(self.__index, 0 < dir ? J : I); - } - self._item = null == self.__item ? null : klass.dual( self.__item, self.__index, n, t, order ); - self._prev = null != self.__item; - if ( self._prev ) self._index = Arithmetic.sub(self._index, I); - return current; - } - - ,hasPrev: function( ) { - return RANDOM & this._order ? false : this._prev; - } - ,range: function( start, end ) { var self = this, Arithmetic = Abacus.Arithmetic, N = Arithmetic.N, O = Arithmetic.O, I = Arithmetic.I, - tmp, tot = self._count, range, count, i, iter_state, dir = 1, + tmp, $ = self.$, tot = $.count, range, count, i, iter_state, dir = 1, argslen = arguments.length, tot_1 = Arithmetic.sub(tot, I), - not_randomised = !(RANDOM & self._order); + not_randomised = !(RANDOM & $.order); if ( argslen < 1 ) { start = O; @@ -1737,10 +1834,11 @@ if ( ('undefined' !== typeof Symbol) && ('undefined' !== typeof Symbol.iterator) Permutation = Abacus.Permutation = Class(CombinatorialIterator, { // extends and implements CombinatorialIterator - constructor: function Permutation( n ) { + constructor: function Permutation( n, $ ) { var self = this; - if ( !(self instanceof Permutation) ) return new Permutation(n); - CombinatorialIterator.call(self, "permutation", n||1); + if ( !(self instanceof Permutation) ) return new Permutation(n, $); + $ = $ || {}; $.type = "permutation"; + CombinatorialIterator.call(self, n||1, $); } ,__static__: { @@ -1750,28 +1848,28 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T - ,count: function( n, type ) { - return factorial( n ); + ,count: function( n, $ ) { + return Abacus.Math.factorial( n ); } - ,initial: function( dir, n, type, order ) { + ,initial: function( dir, n, $ ) { var klass = this, i, item = new Array( n ); if ( 0 > dir ) for(n=n-1,i=0; i<=n; i++) item[i] = n-i; else for(i=0; i 1 ? is_kthroot( item, k-1 ) : false; + } + ,is_connected: function( item ) { + var n = item.length, m = -1, i; + for (i=0; i m ) m = item[i]; // update max. + if ( m <= i ) return false; // prefix mapped to itself, P not connected. + } + return true; // P is connected. + } } }); @@ -1846,10 +1959,12 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { Combination = Abacus.Combination = Class(CombinatorialIterator, { // extends and implements CombinatorialIterator - constructor: function Combination( n, k, type ) { + constructor: function Combination( n, k, $ ) { var self = this; - if ( !(self instanceof Combination) ) return new Combination(n, k, type); - CombinatorialIterator.call(self, String(type||"combination").toLowerCase(), [n||1, k||1]); + if ( !(self instanceof Combination) ) return new Combination(n, k, $); + $ = $ || {}; + $.type = $.type || "combination"; + CombinatorialIterator.call(self, [n||1, k||1], $); } ,__static__: { @@ -1859,11 +1974,11 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T - ,count: function( n, type ) { - return factorial( "repeated" === type ? n[0]+n[1]-1 : n[0], n[1] ); + ,count: function( n, $ ) { + return Abacus.Math.factorial( $ && "repeated" === $.type ? n[0]+n[1]-1 : n[0], n[1] ); } - ,initial: function( dir, n, type, order ) { - var repeated = "repeated" === type, i, k = n[1]-1, item = new Array( k+1 ); + ,initial: function( dir, n, $ ) { + var repeated = $ && "repeated" === $.type, i, k = n[1]-1, item = new Array( k+1 ); if ( 0 > dir ) { n = n[0]-1; @@ -1878,11 +1993,11 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { return item; } ,dual: CombinatorialIterator.dual - ,succ: function( dir, item, index, n, type, order ) { - return next_combination( item, n, dir, "repeated" === type ); + ,succ: function( dir, item, index, n, $ ) { + return next_combination( item, n, dir, $ && "repeated" === $.type ); } - ,rand: function( n, type, total ) { - var item, i, k = n[1], n_k, c, rndInt = Abacus.Math.rndInt, repeated = "repeated" === type; + ,rand: function( n, $ ) { + var item, i, k = n[1], n_k, c, rndInt = Abacus.Math.rndInt, repeated = $ && "repeated" === $.type; n = n[0]; n_k = n-k; c = n-1; if ( repeated ) { @@ -1953,12 +2068,12 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { } return item; } - ,rank: function( item, n, type, total ) { + ,rank: function( item, n, $ ) { var Arithmetic = Abacus.Arithmetic, add = Arithmetic.add, sub = Arithmetic.sub, index = Arithmetic.O, i, c, j, k = n[1], N, binom, - repeated = "repeated" === type; + repeated = $ && "repeated" === $.type, factorial = Abacus.Math.factorial; n = n[0]; N = repeated ? n+k-1 : n; - binom = total ? total : factorial(N, k); + binom = $ && $.count ? $.count : factorial(N, k); if ( repeated ) { for (i=1; i<=k; i++) @@ -1981,14 +2096,14 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { } return sub(sub(binom,Arithmetic.I),index); } - ,unrank: function( index, n, type, total ) { + ,unrank: function( index, n, $ ) { var Arithmetic = Abacus.Arithmetic, O = Arithmetic.O, I = Arithmetic.I, item, binom, k = n[1], N, m, t, p, - repeated = "repeated" === type; + repeated = $ && "repeated" === $.type; n = n[0]; N = repeated ? n+k-1 : n; - total = null != total ? total : factorial(N, k); - item = new Array(k); binom = total; + binom = $ && $.count ? $.count : Abacus.Math.factorial(N, k); + item = new Array(k); // adjust the order to match MSB to LSB index = Arithmetic.sub(Arithmetic.sub(binom,I),index); binom = Arithmetic.div(Arithmetic.mul(binom,N-k),N); @@ -2016,7 +2131,7 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { return complement( n, alpha ); } ,pick: function( a, k, unique, sorted ) { - return pick( a, k, false===unique, true===sorted, true ); + return pick( a, k, false===unique, true===sorted, new Array(k) ); } ,choose: function( arr, comb ) { var i, l = comb.length, chosen = new Array(l); @@ -2032,10 +2147,11 @@ Combination.conjugate = Combination.complement; Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { // extends and implements CombinatorialIterator - constructor: function Subset( n ) { + constructor: function Subset( n, $ ) { var self = this; - if ( !(self instanceof Subset) ) return new Subset(n); - CombinatorialIterator.call(self, "subset", n||1); + if ( !(self instanceof Subset) ) return new Subset(n, $); + $ = $ || {}; $.type = "subset"; + CombinatorialIterator.call(self, n||1, $); } ,__static__: { @@ -2045,35 +2161,35 @@ Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T - ,count: function( n ) { - return pow2( n ); + ,count: function( n, $ ) { + return Abacus.Math.pow2( n ); } - ,initial: function( dir, n, type, order ) { + ,initial: function( dir, n, $ ) { var klass = this, item, i; if ( 0 > dir ) for(item=new Array(n),i=0; i 1 ? 2 : 1), k, m; - for(k=2; k=1; m--) p = add(p, partitions(n, k, m)); - return p; - } - ,initial: function( dir, n, type, order ) { - var klass = this, i, item; - if ( 0 > dir ) item = [ n ]; - else for(item=new Array( n ),i=0; i n) || (M && M > n) || (K && K > n) ) return p; + if ( K ) for(m=M?M:n-K+1; m>=1; m--) p = add(p, partitions(n, K, m)); + else if ( M ) for(m=n-M+1; m>=1; m--) p = add(p, partitions(n, M, m)); + else for(k=1; k<=n; k++) for(m=n-k+1; m>=1; m--) p = add(p, partitions(n, k, m)); + return p; } - ,rand: function( n, type, total ) { - return null; + ,initial: function( dir, n, $ ) { + var klass = this, i, m, k, item, + M = $ && $.max ? $.max|0 : null, + K = $ && $.exactly ? $.exactly|0 : null; + if ( (0 > n) || (K && K > n) || (M && M > n) ) return null; + if ( K ) + { + item = new Array( K ); + if ( 0 > dir ) + { + item[0] = /*M ? M :*/ n-K+1; + for(i=1; i dir ) + { + item[0] = m = Math.ceil(n/K); item[K-1] = Math.floor(n/K); + for(k=K-1,i=1; i dir ) item = [ n ]; + else for(item=new Array( n ),i=0; i n) || (K && K > n) || (M && M > n) ) return null; + return next_partition( item, n, M && !K ? -dir : dir, K ? K : (M && !K ? M : null)/*, M*/ ); } + ,rand: CombinatorialIterator.rand + ,rank: NotImplemented + ,unrank: NotImplemented ,conjugate: conjugatepartition ,pack: packpartition ,unpack: unpackpartition @@ -2159,23 +2316,23 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { self = new Tensor( ); if ( args.length ) { - CombinatorialIterator.call(self, "tensor", args[0] instanceof Array ? args[0] : slice.call(args)); + CombinatorialIterator.call(self, args[0] instanceof Array ? args[0] : slice.call(args), {type:"tensor"}); } else { self.n = []; - self._count = 0; + self.$ = {type:"tensor",count:0,order:LEX}; } return self; } if ( args.length ) { - CombinatorialIterator.call(self, "tensor", args[0] instanceof Array ? args[0] : slice.call(args)); + CombinatorialIterator.call(self, args[0] instanceof Array ? args[0] : slice.call(args), {type:"tensor"}); } else { self.n = []; - self._count = 0; + self.$ = {type:"tensor",count:0,order:LEX}; } } @@ -2184,31 +2341,31 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T - ,count: function( n ) { - return !n || !n.length ? 0 : product( n ); + ,count: function( n, $ ) { + return !n || !n.length ? 0 : Abacus.Math.product( n ); } - ,initial: function( dir, n, type, order ) { + ,initial: function( dir, n, $ ) { var klass = this, i, nd = n.length, item = new Array( nd ); if ( 0 > dir ) for(i=0; i dir ) for(n=n[1]-1,i=0; i=0; i--) diff --git a/src/js/Abacus.min.js b/src/js/Abacus.min.js index 19f169c..aa44a12 100644 --- a/src/js/Abacus.min.js +++ b/src/js/Abacus.min.js @@ -2,7 +2,7 @@ * * Abacus * A combinatorics library for Node/XPCOM/JS, PHP, Python -* @version: 0.5.0 +* @version: 0.5.1 * https://github.com/foo123/Abacus **/ -!function(n,r,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(n.$deps=n.$deps||{})&&(n.EXPORTED_SYMBOLS=[r])&&(n[r]=n.$deps[r]=t.call(n)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[r]=t.call(n)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(r,[],function(e){e(r,t.call(n))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(r)?define(r,["module"],function(r){return t.moduleUri=r.uri,t.call(n)}):r in n||(n[r]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[r]})}(this,"Abacus",function(n){"use strict";function r(){throw new Error("Method not implemented!")}function t(n){if(!arguments.length||null==n)return sn;if(tn(n)){for(var r=0,t=n.toUpperCase().split(","),e=0,i=t.length;i>e;e++)n=t[e],r|=W.call(Y.ORDER,n)?Y.ORDER[n]:0;return r>0?r:sn}return vn&n?n:sn}function e(n,r){if(null==n)return null;if(!n.length)return[];var t,e=n.length,i=new Array(e);if(rn(r))for(t=0;e>t;t++)i[t]=r[t]-1-n[t];else if(0>r)for(t=0;e>t;t++)i[t]=e-1-n[t];else for(r-=1,t=0;e>t;t++)i[t]=r-n[t];return i}function i(n){if(null==n)return null;for(var r=n.length-1,t=new Array(r+1),e=0;r>=e;e++)t[e]=n[r-e];return t}function u(n,r){if(null==r&&(r=0),rn(n)){for(var t=n.length,e=new Array(t),i=0;t>i;i++)e[i]=r-n[i];return e}return n===+n&&r===+r?r-n:Y.Arithmetic.sub(Y.Arithmetic.N(r),n)}function o(n,r,t,e,i){var u,o,l,a=r;if(rn(t)){if(l=t,u=l.length,t=0,e=u-1,i=1,u>0)for(o=t;e>=o;o+=i)a=n(a,l[o])}else if(i=i||1,u=(e-t)/i+1,u>0)if(0>i)for(o=t;o>=e;o+=i)a=n(a,o);else for(o=t;e>=o;o+=i)a=n(a,o);return a}function l(){var n,r,t,e,i,u,o,l,a,f,c=arguments,s=c.length;if(!s)return[];for(a=c[0].length,n=1;s>n;n++)a*=c[n].length;for(f=new Array(a),n=0;a>n;n++){for(l=[],t=n,r=s-1;r>=0;r--)if(e=c[r].length,i=t%e,t=~~(t/e),o=c[r][i],rn(o))for(u=o.length-1;u>=0;u--)l.unshift(o[u]);else l.unshift(o);f[n]=l}return f}function a(n){return o(Y.Arithmetic.mul,Y.Arithmetic.I,n)}function f(n){var r=Y.Arithmetic;return r.shl(r.I,r.N(n))}function c(n,r){var t=Y.Arithmetic;return t.pow(t.N(n),t.N(r))}function s(n,r){var t,e,i,u,l,a=Y.Arithmetic,f=a.O,c=a.I,_=a.N,d=a.add,h=a.sub,m=a.div,v=a.mul;if(null==r)return n=_(n),a.lt(n,0)?f:a.lt(n,2)?c:a.lt(n,4)?a.shl(n,a.sub(n,2)):(l=String(n),null==s.fac[l]&&(s.fac[l]=o(v,c,2,n)),s.fac[l]);if(-1===r)return i=_(n),o(function(n,r){return i===n?n:h(v(n,r),n)},i,n,1,-1);if(-2===r)return l=String(n),null==s.sub[l]&&(s.sub[l]=o(function(r,t){return r[1]=-1===r[2]?h(r[1],r[0]):d(r[1],r[0]),r[2]=-r[2],t>1&&n>=t&&(r[0]=v(r[0],t)),t>n?r[1]:r},[c,f,1],0,n+1)),s.sub[l];if(rn(r)){if(1===r.length)return s(n,r[0]);if(l=String(n)+"@"+r.join(","),null==s.nom[l]){for(t=s(r[0]),u=r.length,i=c,e=1;u>e;e++)i=v(i,s(r[e]));s.nom[l]=m(t,i)}return s.nom[l]}if(+r===r){if(r>n-r&&(r=n-r),0>r||1>n)return f;if(0===r||1===n)return c;if(1===r)return _(n);if(l=String(n)+"@"+String(r),null==s.nom[l]){for(n-=r,i=_(1+n),e=2;r>=e;e++)i=v(i,1+n/e);s.nom[l]=a.round(i)}return s.nom[l]}return f}function _(n,r,t){var e=Y.Arithmetic,i=e.O,u=e.I;if(t===n&&1===r||r===n&&1===t)return u;if(t+r>n+1||n>r*t)return i;var o,l,a=Y.Math,f=e.add,c=a.min(t,n-t-r+2),s=a.max(1,a.ceil((n-t)/(r-1))),d=i;for(o=s;c>=o;o++)l=String(n-t)+","+String(r-1)+","+String(o),null==_.tbl[l]&&(_.tbl[l]=_(n-t,r-1,o)),d=f(d,_.tbl[l]);return d}function d(n,r,t){if(null==r)return null;var t,e,i,u,o=r.length,l=n-o;if(0>=n||0>=l)return t||[];for(t=t||new Array(l),e=0,i=0,u=0;l>u&&n>e;)(i>=o||e!==r[i])&&(t[u++]=e),e++,i++;return t}function h(n,r,t,e,i,u,o,l,a,f){a=!1!==a,l=-1===l?1:0,null==t&&(t=0),null==e&&(e=n.length-1),null==i&&(i=0),null==u&&(u=r.length-1);var c,s=t,_=i,d=e-t+1,h=u-i+1,m=0,v=d+h,p=!a;for(o=o||new Array(v);e>=s&&u>=_;){if(a&&m){if(n[s]===c){s++;continue}if(r[_]===c){_++;continue}}n[s]r[_]?o[m++]=c=l?n[s++]:r[_++]:(o[m++]=c=n[s],p&&(o[m++]=r[_]),s++,_++)}for(;e>=s;)(p||n[s]!==c)&&(o[m++]=c=n[s]),s++;for(;u>=_;)(p||r[_]!==c)&&(o[m++]=c=r[_]),_++;if(!0===f){for(m=0;v>m;m++)n[t+m]=o[m];return n}return m=r)return n;for(var t,e,i=r,u=1,o=2,l=Y.Math.min,a=new Array(r);i;){for(e=r-u,t=0;e>t;t+=o)h(n,n,t,t+u-1,t+u,l(t+o-1,r-1),a,!1,!1,!0);u<<=1,o<<=1,i>>=1}return n}function v(n,r,t){var e,i,u,o,l,a=Y.Math.rndInt;for(o=!0===t?n.slice():n,l=!0===r?1:0,e=o.length;ll;l++)u[l]=n[c(0,s)];return e&&m(u),u}for(i=!1!==i,i&&(o=new Array(r)),l=0;r>l;l++)a=c(0,--s),f=n[a],n[a]=n[s],n[s]=f,u[l]=f,i&&(o[l]=a);if(i)for(l=r-1;l>=0;l--)a=o[l],f=n[s],n[s]=n[a],n[a]=f,s++;return e&&m(u),u}function g(n){if(null==n)return null;var r,t,e,i=n.length,u=n[0],o=new Array(u);for(r=0;u>r;r++)o[r]=1;for(t=1;i>t;t++)for(r=0,e=n[t];u>r&&e>0;)o[r++]++,e--;return o}function A(n){var r,t=[],e=n.length,i=n[0],u=[i,1];for(r=1;e>r;r++)i===n[r]?u[1]++:(t.push(u),i=n[r],u=[i,1]);return t.push(u),t}function y(n){var r,t,e,i,u,o=[],l=n.length;for(r=0;l>r;r++)if(u=n[r],1===u[1])o.push(u[0]);else for(e=u[1],i=u[0],t=0;e>t;t++)o.push(i);return o}function w(n){var r,t,e,i,u=n.length,o=new Array(u),l=Y.Math.ceil(en(u)),a=(1<<1+l)-1,f=new Array(a),c=1<r;r++)f[r]=0;for(r=0;u>r;r++){for(i=n[r],e=c+i,t=0;l>t;t++)1&e&&(i-=f[e>>>1<<1]),f[e]+=1,e>>>=1;f[e]+=1,o[r]=i}return o}function b(n){var r,t,e,i,u,o,l,a,f,c=n.length,s=new Array(c);for(o=Y.Math.ceil(en(c)),l=(1<<1+o)-1,a=new Array(l),f=1<=r;r++)for(t=1,e=1<=t;t++)a[e-1+t]=1<r;r++){for(i=n[r],u=1,t=0;o>t;t++)a[u]-=1,u<<=1,i>=a[u]&&(i-=a[u],u++);a[u]=0,s[r]=u-f}return s}function x(n,r,t){var e,i=n.length,u=null==r;if(i>1)for(u&&(r=new Array(i-1),t=0),e=i-1;e>=1;e--)r[t++]=[n[0],n[e]];else u&&(r=[]);return u?r:t}function M(n,r){var t,e,i,u,o=n.length,l=new Array(o),a=!0===r?1:0,f=new Array(o),c=0,s=0;for(t=0;o>t;t++)f[t]=0;for(i=new Array(o),u=0,e=c++,i[u++]=e,f[e]=1;o>c;){if(e=n[e],f[e])for(u>a&&(i.length=u,l[s++]=i),i=new Array(o),u=0;o>c&&f[e=c];)++c;f[e]||(i[u++]=e,f[e]=1)}return u>a&&(i.length=u,l[s++]=i),sr;r++)u=x(o[r],i,u);return ut;t++)o[t]=t;for(t=0;u>t;t++)swap=e[t],i=o[e[0]],o[e[0]]=o[e[1]],o[e[1]]=i;return o}function O(n,r){var t,e,i=n.length,u=new Array(i);for(t=0;i>t;t++)for(u[t]=new Array(i),e=0;i>e;e++)u[t][e]=0;if(!0===r)for(t=0;i>t;t++)u[n[t]][t]=1;else for(t=0;i>t;t++)u[t][n[t]]=1;return u}function C(n,r){var t,e,i=n.length,u=new Array(i);if(!0===r)for(t=0;i>t;t++)for(e=0;i>e;e++)n[t][e]&&(u[e]=t);else for(t=0;i>t;t++)for(e=0;i>e;e++)n[t][e]&&(u[t]=e);return u}function R(n){var r,t=n.length,e=new Array(t);for(r=0;t>r;r++)e[n[r]]=r;return e}function S(n,r){if(r=r||n.length,r!==n.length)return!1;var t,e,i=new Array(r);for(t=0;r>t;t++)i[t]=0;for(t=0;r>t;t++){if(e=n[t],0>e||e>=r||0!==i[e])return!1;i[e]++}for(t=0;r>t;t++)if(1!==i[t])return!1;return!0}function T(n){var r,t,e,i=n,u=i.length,o=u?i[0]:[],l=o.length;for(t=1;u>t;t++)for(e=o.slice(),r=0;l>r;r++)o[r]=e[i[t][r]];return o}function k(n){var r,t,e,i,u,o,l=n,a=l.length,f=0;for(e=0;a>e;e++)f+=l[e].length;for(r=new Array(f),i=0,e=0;a>e;e++){for(u=l[e],o=u.length,t=0;o>t;t++)r[i+t]=i+u[t];i+=o}return r}function P(n){for(var r=n.length,t=0;r>t;t++)if(n[t]!==t)return!1;return!0}function L(n,r){r=r||1;var t,e=new Array(r+1);for(t=0;r>=t;t++)e[t]=n;return P(T(e))}function N(n){for(var r=n.length,t=0;r>t;t++)if(n[t]===t)return!1;return!0}function X(n,r,t){if(n){var e,i,u,o,l,a=r,f=n.slice();if(0>t){for(e=a-2;e>=0&&n[e]<=n[e+1];)e--;if(e>=0){for(i=a-1;i>e&&n[e]<=n[i];)i--;for(l=f[e],f[e]=f[i],f[i]=l,u=e+1,o=a-1;o>u;)l=f[u],f[u++]=f[o],f[o--]=l}else f=null}else{for(e=a-2;e>=0&&n[e]>=n[e+1];)e--;if(e>=0){for(i=a-1;i>e&&n[e]>=n[i];)i--;for(l=f[e],f[e]=f[i],f[i]=l,u=e+1,o=a-1;o>u;)l=f[u],f[u++]=f[o],f[o--]=l}else f=null}return f}return null}function q(n,r,t,e){if(n){var i,u,o,l,a=r[1],f=r[0],c=e?0:1,s=n.slice();if(0>t){for(i=a-1,u=-1;i>0;){if(s[i]>s[i-1]+c){u=i;break}i--}if(-1===u&&0-1){for(l=f-1+c,i=a-1;i>u;i--)l-=c,s[i]=l;s[u]--}else s=null}else{if(i=a-1,u=-1,e)for(;i>=0;){if(s[i]=0;){if(s[i]-1)for(l=s[u]+1-c,i=u;a>i;i++)l+=c,s[i]=l;else s=null}return s}return null}function j(n,r,t){if(n){var e,i,u=n.slice(),o=r,l=o.length;if(0>t){for(e=l-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;l>i;i++)u[i]=o[i]-1;else u=null}else{for(e=l-1;e>=0&&u[e]+1===o[e];)e--;if(e>=0)for(u[e]++,i=e+1;l>i;i++)u[i]=0;else u=null}return u}return null}function J(n,r,t){if(n){var e,i,u=n.slice(),o=r[0],l=r[1];if(0>t){for(e=o-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,l--,i=e+1;o>i;i++)u[i]=l;else u=null}else{for(e=o-1;e>=0&&u[e]+1===l;)e--;if(e>=0)for(u[e]++,i=e+1;o>i;i++)u[i]=0;else u=null}return u}return null}function V(n,r,t){if(n){var e,i,u,o,l,a,f=r,c=n.slice();if(0>t)if(c[0]>1){for(i=c.length,e=i-1;e>=0&&1===c[e];)e--;for(u=c[e]-1,c=c.slice(0,e+1),c[e]=u,l=0,e=0,i=c.length;i>e;e++)l+=c[e];for(a=f-l;a>0;)o=a,o>u?(o=u,c.push(o)):c.push(a),a-=o}else c=null;else if(c[0]0&&e--;e>0&&c[e]===c[e-1];)e--;for(c[e]++,c=c.slice(0,e+1),l=0,e=0,i=c.length;i>e;e++)l+=c[e];for(a=f-l;a>0;)c.push(1),a--}else c=null;return c}return null}var D,G,H,F,$,B,U,Y={VERSION:"0.5.0"},z="prototype",K="constructor",Q=Array.prototype.slice,W=Object[z].hasOwnProperty,Z=Object[z].toString,nn=/^\s+|\s+$/g,rn=(String.prototype.trim?function(n){return n.trim()}:function(n){return n.replace(nn,"")},function(n){return n instanceof Array||"[object Array]"===Z.call(n)}),tn=function(n){return n instanceof String||"[object String]"===Z.call(n)},en=Math.log2||function(n){return Math.log(n)/Math.LN2},un=function(n){var r=n.toString(2),t=32-r.length;return t>0?new Array(t+1).join("0")+r:r},on=Object.create,ln=function(n,r){for(var t in r)W.call(r,t)&&(n[t]=r[t]);return n},an=function(n,r){1===arguments.length&&(r=n,n=Object);var t=r[K];return W.call(r,"__static__")&&(t=ln(t,r.__static__),delete r.__static__),t[z]=ln(on(n[z]),r),t},fn=1,cn=2,sn=4,_n=8,dn=16,hn=32,mn=sn|_n|dn,vn=mn|hn|fn|cn;return s.fac={},s.sub={},s.nom={},_.tbl={},Y.ORDER={LEX:sn,LEXICOGRAPHIC:sn,REVLEX:sn|fn,ANTILEX:sn|fn,REVERSELEXICOGRAPHIC:sn|fn,ANTILEXICOGRAPHIC:sn|fn,REFLEX:sn|cn,REFLECTEDLEXICOGRAPHIC:sn|cn,COLEX:_n,COLEXICOGRAPHIC:_n,REVCOLEX:_n|fn,ANTICOLEX:_n|fn,REVERSECOLEXICOGRAPHIC:_n|fn,ANTICOLEXICOGRAPHIC:_n|fn,REFCOLEX:_n|cn,REFLECTEDCOLEXICOGRAPHIC:_n|cn,REV:fn,REVERSE:fn,REVERSED:fn,REF:cn,REFLECT:cn,REFLECTED:cn,RANDOM:hn},Y.Math={O:0,I:1,J:-1,N:function(n){return Y.Arithmetic.add(Y.Arithmetic.O,n)},V:function(n){return Y.Arithmetic.sub(Y.Arithmetic.O,n)},rnd:Math.random,rndInt:function(n,r){return Y.Math.round((r-n)*Y.Math.rnd()+n)},equ:function(n,r){return n===r},gte:function(n,r){return n>=r},lte:function(n,r){return r>=n},gt:function(n,r){return n>r},lt:function(n,r){return r>n},inside:function(n,r,t,e){return e?n>=r&&t>=n:n>r&&t>n},clamp:function(n,r,t){return r>n?r:n>t?t:n},wrap:function(n,r,t){return r>n?t:n>t?r:n},wrapR:function(n,r){return 0>n?n+r:n},add:function(n,r){return n+r},sub:function(n,r){return n-r},mul:function(n,r){return n*r},div:function(n,r){return Y.Math.floor(n/r)},mod:function(n,r){return n%r},pow:Math.pow,shl:function(n,r){return n<>r},bor:function(n,r){return n|r},band:function(n,r){return n&r},xor:function(n,r){return n^r},abs:Math.abs,min:Math.min,max:Math.max,floor:Math.floor,ceil:Math.ceil,round:Math.round,num:function(n){return"number"==typeof n?Y.Math.floor(n):parseInt(n,10)},val:function(n){return Y.Math.floor(n.valueOf())}},Y.Arithmetic={O:0,I:1,J:-1,N:Y.Math.N,V:Y.Math.V,equ:Y.Math.equ,gte:Y.Math.gte,lte:Y.Math.lte,gt:Y.Math.gt,lt:Y.Math.lt,inside:Y.Math.inside,clamp:Y.Math.clamp,wrap:Y.Math.wrap,wrapR:Y.Math.wrapR,add:Y.Math.add,sub:Y.Math.sub,mul:Y.Math.mul,div:Y.Math.div,mod:Y.Math.mod,pow:Y.Math.pow,shl:Y.Math.shl,shr:Y.Math.shr,bor:Y.Math.bor,band:Y.Math.band,xor:Y.Math.xor,abs:Y.Math.abs,min:Y.Math.min,max:Y.Math.max,floor:Y.Math.floor,ceil:Y.Math.ceil,round:Y.Math.round,rnd:Y.Math.rndInt,num:Y.Math.num,val:Y.Math.val},Y.BitArray=an({constructor:function pn(n){var r=this;return r instanceof pn?(r.length=n,void(r.bits=new Uint32Array(Y.Math.ceil(n/32)))):new pn(n)},length:0,bits:null,dispose:function(){var n=this;return n.length=null,n.bits=null,n},clone:function(){var n=this,r=new Y.BitArray(n.length);return r.bits=new Uint32Array(n.bits),r},fromArray:function(n){var r=this;return r.bits=new Uint32Array(n),r},toArray:function(){return Q.call(this.bits)},toString:function(){var n,r,t=this.toArray();for(n=0,r=t.length;r>n;n++)t[n]=un(t[n]);return t.join("")},reset:function(){var n,r=this,t=r.bits,e=t.length;for(n=0;e>n;n++)t[n]=0;return r},isset:function(n){return!!(this.bits[n>>>5]&1<<(31&n))},set:function(n){var r=this;return r.bits[n>>>5]|=1<<(31&n),r},unset:function(n){var r=this;return r.bits[n>>>5]&=~(1<<(31&n)),r},toggle:function(n){var r=this;return r.bits[n>>>5]^=1<<(31&n),r}}),D=Y.CombinatorialIterator=an({constructor:function(n,r,t,e){var i=this,u=i[K];i.type=String(n),i.n=r||0,i.options=t||{},i._count=u.count(i.n,i.type),i.order(i.options.order||e||sn)},__static__:{Iterable:function gn(n){var r=this;return r instanceof gn?void(r.next=function(){return n.hasNext()?{value:n.next()}:{done:!0}}):new gn(n)},C:function(n,r){return e(n,r)},P:function(n,r){return i(n)},T:function(n,r){return u(n,r)},count:r,initial:r,rank:r,unrank:r,dual:function(n,r,t,e,i){if(null==n)return null;var u=this,o=u.C,l=u.P;u.T;return i=0|i,hn&i?cn&i?l(n,t):n:_n&i?cn&i?o(n,t):l(o(n,t),t):cn&i?l(n,t):n.slice()},succ:function(n,r,t,e,i,u,o){var l=this,a=Y.Arithmetic;return null==r?null:l.unrank(a.add(t,0>n?a.J:a.I),e,i,o)},rand:function(n,r,t){var e=this,i=Y.Arithmetic,u=null!=t?t:e.count(n,r);return e.unrank(i.rnd(i.O,i.sub(u,i.I)),n,r,u)}},type:null,options:null,n:0,_order:0,_count:0,__index:null,_index:null,__item:null,_item:null,_prev:null,_next:null,_traversed:null,dispose:function(){var n=this;return n.type=null,n.options=null,n.n=null,n._order=null,n._count=0,n.__index=null,n._index=null,n.__item=null,n._item=null,n._prev=null,n._next=null,n._traversed&&(n._traversed.dispose(),n._traversed=null),n},_store:function(){var n=this;return[n._order,n.__index,n._index,n.__item,n._item,n._prev,n._next,n.n]},_restore:function(n){var r=this;return n&&(r._order=n[0],r.__index=n[1],r._index=n[2],r.__item=n[3],r._item=n[4],r._prev=n[5],r._next=n[6],r.n=n[7]),r},total:function(){return this._count},order:function(n,r){if(!arguments.length)return this._order;var e,i,u,o,l,a,f=this,c=Y.Arithmetic,s=c.O,_=c.I,d=f[K];d.T;return r=!1===r,n=t(n),i=f._count,o=f.n,l=f.type,u=c.sub(i,_),a=fn&n?-1:1,a=r?-a:a,f._order=n,f.__index=f._index=s,f._item=f.__item=null,f._prev=!1,f._next=!1,hn&n?(c.gt(i,1e6)?(f._traversed&&(f._traversed.dispose(),f._traversed=null),e=f.randomIndex()):(f._traversed?f._traversed.reset():f._traversed=new Y.BitArray(i),f._traversed.set(e=f.randomIndex())),f.__item=d.unrank(e,o,l,i),null!=f.__item&&(f.__index=e)):_n&n?(f.__item=d.initial(-a,o,l,n),null!=f.__item&&(f.__index=-1===a?s:u)):(f.__item=d.initial(a,o,l,n),null!=f.__item&&(f.__index=-1===a?u:s)),f._item=null==f.__item?null:d.dual(f.__item,f.__index,o,l,n),f._index=!r||hn&n?s:u,f._prev=hn&n||!r?!1:null!=f.__item,f._next=!r||hn&n?null!=f.__item:!1,f},index:function(n){if(!arguments.length)return this._index;var r,t=this,e=Y.Arithmetic,i=e.O,u=e.I,o=e.J,l=t[K],a=(l.T,t.n),f=t.type,c=t._count,s=t._order,_=fn&s?-1:1;return n=e.wrapR(e.N(n),c),!e.equ(n,t._index)&&e.inside(n,o,c)&&(r=e.sub(c,u),_n&s?(t.__index=-1===_?n:e.sub(r,n),t._index=n,t.__item=e.equ(i,n)?l.initial(-_,a,f,s):e.equ(r,n)?l.initial(_,a,f,s):l.unrank(t.__index,a,f,c),t._item=l.dual(t.__item,t.__index,a,f,s),t._prev=null!=t.__item,t._next=null!=t.__item):hn&s||(t.__index=-1===_?e.sub(r,n):n,t._index=n,t.__item=e.equ(i,n)?l.initial(_,a,f,s):e.equ(r,n)?l.initial(-_,a,f,s):l.unrank(t.__index,a,f,c),t._item=l.dual(t.__item,t.__index,a,f,s),t._prev=null!=t.__item,t._next=null!=t.__item)),t},item:function(n,r){if(!arguments.length)return this._item;var e,i,u,o=this,l=o.n,a=o.type,f=o._count,c=o[K],s=(c.T,Y.Arithmetic),_=s.O,d=s.I,h=s.J;return r=null!=r?t(r):o._order,n=s.wrapR(s.N(n),f),r===o._order&&s.equ(n,o._index)?o._item:s.inside(n,h,f)?(i=fn&r?-1:1,e=s.sub(f,d),hn&r?(u=o.randomIndex(),c.dual(c.unrank(u,l,a,f),u,l,a,r)):_n&r?(u=-1===i?n:s.sub(e,n),c.dual(s.equ(_,n)?c.initial(-i,l,a,r):s.equ(e,n)?c.initial(i,l,a,r):c.unrank(u,l,a,f),u,l,a,r)):(u=-1===i?s.sub(e,n):n,c.dual(s.equ(_,n)?c.initial(i,l,a,r):s.equ(e,n)?c.initial(-i,l,a,r):c.unrank(u,l,a,f),u,l,a,r))):null},randomIndex:function(n,r){var t=this,e=Y.Arithmetic,i=e.N,u=e.O,o=e.I,l=t._count,a=arguments.length;return 0===a?(n=u,r=e.sub(l,o)):1===a?(n=i(n||0),r=e.sub(l,o)):(n=i(n),r=i(r)),e.rnd(n,r)},random:function(){var n=this,r=n[K];return r.dual(r.rand(n.n,n.type,n._count),null,n.n,n.type,hn|n._order)},rewind:function(){return this.order(this._order,!0)},next:function(){var n,r,t,e,i,u=this,o=Y.Arithmetic,l=o.O,a=o.I,f=o.J,c=u._order,s=u[K],_=(s.T,u._item),d=u.n,h=u.type,m=u._count;if(hn&c)if(e=o.sub(m,a),o.lt(u._index,e))if(n=u._traversed){for(r=u.randomIndex(),i=Y.Math.rnd()>.5?f:a;n.isset(r);)r=o.wrap(o.add(r,i),l,e);n.set(r),u.__item=s.unrank(r,d,h,m),null!=u.__item&&(u.__index=r)}else r=u.randomIndex(),u.__item=s.unrank(r,d,h,m),null!=u.__item&&(u.__index=r);else u._item=u.__item=null,u._traversed&&(u._traversed.dispose(),u._traversed=null);else t=fn&c?-1:1,_n&c?(u.__item=s.succ(-t,u.__item,u.__index,d,h,c,m),null!=u.__item&&(u.__index=o.add(u.__index,t>0?f:a))):(u.__item=s.succ(t,u.__item,u.__index,d,h,c,m),null!=u.__item&&(u.__index=o.add(u.__index,0>t?f:a)));return u._item=null==u.__item?null:s.dual(u.__item,u.__index,d,h,c),u._next=null!=u.__item,u._next&&(u._index=o.add(u._index,a)),_},hasNext:function(){return this._next},forward:function(){return this.order(this._order,!1)},prev:function(){var n,r=this,t=Y.Arithmetic,e=t.I,i=t.J,u=r._order,o=r[K],l=(o.T,r._item),a=r.n,f=r.type,c=r._count;return hn&u?null:(n=fn&u?-1:1,_n&u?(r.__item=o.succ(n,r.__item,r.__index,a,f,u,c),null!=r.__item&&(r.__index=t.add(r.__index,0>n?i:e))):(r.__item=o.succ(-n,r.__item,r.__index,a,f,u,c),null!=r.__item&&(r.__index=t.add(r.__index,n>0?i:e))),r._item=null==r.__item?null:o.dual(r.__item,r.__index,a,f,u),r._prev=null!=r.__item,r._prev&&(r._index=t.sub(r._index,e)),l)},hasPrev:function(){return hn&this._order?!1:this._prev},range:function(n,r){var t,e,i,u,o,l=this,a=Y.Arithmetic,f=a.N,c=a.O,s=a.I,_=l._count,d=1,h=arguments.length,m=a.sub(_,s),v=!(hn&l._order);if(1>h?(n=c,r=m):2>h?(n=f(n),r=m):(n=f(n),r=f(r)),n=a.wrapR(n,_),r=a.wrapR(r,_),a.gt(n,r)&&(t=n,n=r,r=t,d=-1),n=a.clamp(n,c,m),v&&(r=a.clamp(r,c,m)),a.lte(n,r)){if(o=l._store(),v&&l.index(n),i=a.val(a.sub(r,n)),e=new Array(i+1),0>d)for(u=i;u>=0;u--)e[u]=l.next();else for(u=0;i>=u;u++)e[u]=l.next();l._restore(o)}else e=[];return e},__iter__:function(){return new D.Iterable(this)}}),"undefined"!=typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(D[z][Symbol.iterator]=D[z].__iter__),G=Y.Permutation=an(D,{constructor:function An(n){var r=this;return r instanceof An?void D.call(r,"permutation",n||1):new An(n)},__static__:{C:function(n,r){return e(n,-1)},P:D.P,T:D.T,count:function(n,r){return s(n)},initial:function(n,r,t,e){var i,u=new Array(r);if(0>n)for(r-=1,i=0;r>=i;i++)u[i]=r-i;else for(i=0;r>i;i++)u[i]=i;return u},dual:D.dual,succ:function(n,r,t,e,i,u){return X(r,e,n)},rand:function(n,r,t){var e,i;Y.Math.rndInt;for(i=new Array(n),e=0;n>e;e++)i[e]=e;return v(i,!1,!1),i},rank:function(n,r,t,e){var i,u,o,l=Y.Arithmetic;if(r=r||n.length,!r)return l.J;for(n=w(n),i=l.O,o=r-1,u=0;o>u;u++)i=l.add(l.mul(i,r-u),n[u]);return i},unrank:function(n,r,t,e){var i,u,o,l,a,f=Y.Arithmetic;if(!r)return[];for(i=new Array(r),i[r-1]=0,u=n,o=r-2;o>=0;o--)l=r-o,a=f.mod(u,l),u=f.div(u,l),i[o]=f.val(a);return b(i)},permute:function(n,r,t){var e,i,u,o=n.length;for(!0===t?(i=new Array(o),u=n):(i=n,u=n.slice()),e=0;o>e;e++)i[e]=u[r[e]];return i},shuffle:function(n,r){return v(n,!0===r,!1)},compose:function(){return T(arguments)},concatenate:function(){return k(arguments)},inverse:function(n){return R(n)},cycles:function(n,r){return-1===r?cycles2permutation(n):M(n)},swaps:function(n,r){return-1===r?E(n):I(n)},inversion:function(n,r){return-1===r?b(n):w(n)},matrix:function(n,r,t){return-1===t?C(n,r):O(n,r)},is_permutation:S,is_identity:P,is_derangement:N,is_involution:L}}),H=Y.Combination=an(D,{constructor:function yn(n,r,t){var e=this;return e instanceof yn?void D.call(e,String(t||"combination").toLowerCase(),[n||1,r||1]):new yn(n,r,t)},__static__:{C:function(n,r){return e(n,r[0])},P:D.P,T:D.T,count:function(n,r){return s("repeated"===r?n[0]+n[1]-1:n[0],n[1])},initial:function(n,r,t,e){var i,u="repeated"===t,o=r[1]-1,l=new Array(o+1);if(0>n)if(r=r[0]-1,u)for(i=0;o>=i;i++)l[i]=r;else for(i=0;o>=i;i++)l[o-i]=r-i;else if(u)for(i=0;o>=i;i++)l[i]=0;else for(i=0;o>=i;i++)l[i]=i;return l},dual:D.dual,succ:function(n,r,t,e,i,u){return q(r,e,n,"repeated"===i)},rand:function(n,r,t){var e,i,u,o,l=n[1],a=Y.Math.rndInt,f="repeated"===r;if(n=n[0],u=n-l,o=n-1,f)if(1===l)e=[a(0,o)];else{for(e=new Array(l),i=0;l>i;i++)e[i]=a(0,o);m(e)}else{var c,s,_;if(1===l)e=[a(0,o)];else if(n===l)for(e=new Array(l),i=0;l>i;i++)e[i]=i;else if(l>u){for(c={},_=new Array(u),i=0;u>i;i++){do s=a(0,o);while(1===c[s]);c[s]=1,_[i]=s}e=d(n,m(_))}else{for(c={},e=new Array(l),i=0;l>i;i++){do s=a(0,o);while(1===c[s]);c[s]=1,e[i]=s}m(e)}}return e},rank:function(n,r,t,e){var i,u,o,l,a,f=Y.Arithmetic,c=f.add,_=f.sub,d=f.O,h=r[1],m="repeated"===t;if(r=r[0],l=m?r+h-1:r,a=e?e:s(l,h),m)for(i=1;h>=i;i++)u=l-1-n[i-1]-i+1,o=h+1-i,u>=o&&(d=c(d,s(u,o)));else for(i=1;h>=i;i++)u=l-1-n[i-1],o=h+1-i,u>=o&&(d=c(d,s(u,o)));return _(_(a,f.I),d)},unrank:function(n,r,t,e){var i,u,o,l,a,f,c=Y.Arithmetic,_=c.O,d=c.I,h=r[1],m="repeated"===t;r=r[0],o=m?r+h-1:r,e=null!=e?e:s(o,h),i=new Array(h),u=e,n=c.sub(c.sub(u,d),n),u=c.div(c.mul(u,o-h),o),a=o-h+1,l=h,f=o-1;do c.lte(u,n)?(i[h-l]=m?o-a-h+1:o-a-l+1,c.gt(u,_)&&(n=c.sub(n,u),u=c.div(c.mul(u,l),f)),l--,f--):(u=c.div(c.mul(u,f-l),f),a--,f--);while(l>0);return i},complement:function(n,r){return d(r,n)},pick:function(n,r,t,e){return p(n,r,!1===t,!0===e,!0)},choose:function(n,r){var t,e=r.length,i=new Array(e);for(t=0;e>t;t++)i[t]=n[r[t]];return i}}}),H.conjugate=H.complement,$=Y.Powerset=Y.Subset=an(D,{constructor:function wn(n){var r=this;return r instanceof wn?void D.call(r,"subset",n||1):new wn(n)},__static__:{C:function(n,r){return d(r,n)},P:D.P,T:D.T,count:function(n){return f(n)},initial:function(n,r,t,e){var i,u;if(0>n)for(i=new Array(r),u=0;r>u;u++)i[u]=u;else i=[];return i},dual:function(n,r,t,e,i){if(null==n)return null;var u=this,o=u.C,l=u.P;u.T;return i=0|i,hn&i?cn&i?n:l(n,t):_n&i?cn&i?l(o(n,t),t):o(n,t):cn&i?n.slice():l(n,t)},succ:D.succ,rand:D.rand,rank:function(n,r,t,e){for(var i=Y.Arithmetic,u=i.O,o=i.I,l=u,a=0,f=subset.length;f>a;)l=i.add(l,i.shl(o,subset[a++]));return l},unrank:function(n,r,t,e){var i=this,u=Y.Arithmetic,o=u.O,l=[],a=0;if(!u.inside(n,u.J,null!=e?e:i.count(r)))return null;for(;u.gt(n,o);)u.gt(u.band(n,1),o)&&l.push(a),u.gt(u.band(n,2),o)&&l.push(a+1),u.gt(u.band(n,4),o)&&l.push(a+2),u.gt(u.band(n,8),o)&&l.push(a+3),u.gt(u.band(n,16),o)&&l.push(a+4),u.gt(u.band(n,32),o)&&l.push(a+5),u.gt(u.band(n,64),o)&&l.push(a+6),u.gt(u.band(n,128),o)&&l.push(a+7),a+=8,n=u.shr(n,8);return l}}}),F=Y.Partition=an(D,{constructor:function bn(n){var r=this;return r instanceof bn?void D.call(r,"partition",n||1):new bn(n)},__static__:{C:function(n,r){return g(n)},P:D.P,T:D.T,count:function(n,r){var t,e,i=Y.Arithmetic.add,u=Y.Arithmetic.N(n>1?2:1);for(t=2;n>t;t++)for(e=n-t+1;e>=1;e--)u=i(u,_(n,t,e));return u},initial:function(n,r,t,e){var i,u;if(0>n)u=[r];else for(u=new Array(r),i=0;r>i;i++)u[i]=1;return u},dual:function(n,r,t,e,i){return null==n?null:n.slice()},succ:function(n,r,t,e,i,u){return V(r,e,n)},rand:function(n,r,t){return null},rank:function(n,r,t,e){return Y.Arithmetic.J},unrank:function(n,r,t,e){return null},conjugate:g,pack:A,unpack:y}}),F.transpose=F.conjugate,B=Y.Tensor=an(D,{constructor:function xn(){var n=this,r=arguments;return n instanceof xn?void(r.length?D.call(n,"tensor",r[0]instanceof Array?r[0]:Q.call(r)):(n.n=[],n._count=0)):(n=new xn,r.length?D.call(n,"tensor",r[0]instanceof Array?r[0]:Q.call(r)):(n.n=[],n._count=0),n)},__static__:{C:D.C,P:D.P,T:D.T,count:function(n){return n&&n.length?a(n):0},initial:function(n,r,t,e){var i,u=r.length,o=new Array(u);if(0>n)for(i=0;u>i;i++)o[i]=r[i]-1;else for(i=0;u>i;i++)o[i]=0;return o},dual:D.dual,succ:function(n,r,t,e,i,u){return j(r,e,n)},rand:function(n,r,t){var e,i=Y.Math.rndInt,u=n.length,o=new Array(u);for(e=0;u>e;e++)o[e]=i(0,n[e]-1);return o},rank:function(n,r,t,e){var i,u,o=Y.Arithmetic,l=r.length;if(!l)return o.J;for(i=o.O,u=0;l>u;u++)i=o.add(o.mul(i,r[u]),n[u]);return i},unrank:function(n,r,t,e){var i,u,o,l,a,f=Y.Arithmetic,c=r.length;if(!c)return[];for(a=new Array(c),i=n,o=c-1;o>=0;o--)u=r[o],l=f.mod(i,u),i=f.div(i,u),a[o]=f.val(l);return a},product:l,component:function(n,r){var t,e,i,u,o,l,a=[],f=r,c=f.length;for(t=0;c>t;t++)if(i=f[t],o=n[t],u=i[o],u instanceof Array)for(e=0,l=u.length;l>e;e++)a.push(u[e]);else a.push(u);return a}}}),U=Y.Tuple=an(D,{constructor:function Mn(n,r){var t=this;return t instanceof Mn?void D.call(t,"tuple",[n||1,r||2]):new Mn(n,r)},__static__:{C:function(n,r){return e(n,r[1])},P:D.P,T:D.T,count:function(n){return c(n[0],n[1])},initial:function(n,r,t,e){var i,u=r[0],o=new Array(u);if(0>n)for(r=r[1]-1,i=0;u>i;i++)o[i]=r;else for(i=0;u>i;i++)o[i]=0;return o},dual:D.dual,succ:function(n,r,t,e,i,u){return J(r,e,n)},rand:function(n,r,t){var e,i=Y.Math.rndInt,u=n[0],o=n[1]-1,l=new Array(u);for(e=0;u>e;e++)l[e]=i(0,o);return l},rank:function(n,r,t,e){var i,u,o=Y.Arithmetic,l=r[0],a=r[1];for(i=o.O,u=0;l>u;u++)i=o.add(o.mul(i,a),n[u]);return i},unrank:function(n,r,t,e){var i,u,o,l,a=Y.Arithmetic,f=r[1],c=r[0];for(l=new Array(c),i=n,u=c-1;u>=0;u--)o=a.mod(i,f),i=a.div(i,f),l[u]=a.val(o);return l}}}),Y}); \ No newline at end of file +!function(n,r,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(n.$deps=n.$deps||{})&&(n.EXPORTED_SYMBOLS=[r])&&(n[r]=n.$deps[r]=t.call(n)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[r]=t.call(n)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(r,[],function(e){e(r,t.call(n))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(r)?define(r,["module"],function(r){return t.moduleUri=r.uri,t.call(n)}):r in n||(n[r]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[r]})}(this,"Abacus",function(n){"use strict";function r(){throw new Error("Method not implemented!")}function t(n){if(!arguments.length||null==n)return _n;if(un(n)){for(var r=0,t=n.toUpperCase().split(","),e=0,i=t.length;i>e;e++)n=t[e],r|=nn.call(K.ORDER,n)?K.ORDER[n]:0;return r>0?r:_n}return gn&n?n:_n}function e(n,r){if(null==n)return null;if(!n.length)return[];var t,e=n.length,i=new Array(e);if(en(r))for(t=0;e>t;t++)i[t]=r[t]-1-n[t];else if(0>r)for(t=0;e>t;t++)i[t]=e-1-n[t];else for(r-=1,t=0;e>t;t++)i[t]=r-n[t];return i}function i(n){if(null==n)return null;for(var r=n.length-1,t=new Array(r+1),e=0;r>=e;e++)t[e]=n[r-e];return t}function u(n,r){if(null==r&&(r=0),en(n)){for(var t=n.length,e=new Array(t),i=0;t>i;i++)e[i]=r-n[i];return e}return n===+n&&r===+r?r-n:K.Arithmetic.sub(K.Arithmetic.N(r),n)}function o(n,r,t,e,i,u){var o,l,a=r;if(t&&en(t)){if(o=t.length,null==e&&(e=0),null==i&&(i=o-1),null==u&&(u=1),o>0)if(0>u)for(l=e;l>=i;l+=u)a=n(a,t[l],l);else for(l=e;i>=l;l+=u)a=n(a,t[l],l)}else if(u=u||1,o=(i-e)/u+1,o>0)if(0>u)for(l=e;l>=i;l+=u)a=n(a,l,l);else for(l=e;i>=l;l+=u)a=n(a,l,l);return a}function l(){var n,r,t,e,i,u,o,l,a,f,c=arguments,s=c.length;if(!s)return[];for(a=c[0].length,n=1;s>n;n++)a*=c[n].length;for(f=new Array(a),n=0;a>n;n++){for(l=[],t=n,r=s-1;r>=0;r--)if(e=c[r].length,i=t%e,t=~~(t/e),o=c[r][i],en(o))for(u=o.length-1;u>=0;u--)l.unshift(o[u]);else l.unshift(o);f[n]=l}return f}function a(n){return o(K.Arithmetic.add,K.Arithmetic.O,n)}function f(n){return o(K.Arithmetic.mul,K.Arithmetic.I,n)}function c(n){var r=K.Arithmetic;return r.shl(r.I,r.N(n))}function s(n,r){var t=K.Arithmetic;return t.pow(t.N(n),t.N(r))}function d(n,r){var t,e,i,u,l,a=K.Arithmetic,f=a.O,c=a.I,s=a.N,_=a.add,h=a.sub,m=a.div,v=a.mul;if(null==r)return n=s(n),a.lt(n,0)?f:a.lt(n,2)?c:a.lt(n,4)?a.shl(n,a.sub(n,2)):(l=String(n),null==d.fac[l]&&(d.fac[l]=o(v,c,null,2,n)),d.fac[l]);if(-1===r)return i=s(n),o(function(n,r){return i===n?n:h(v(n,r),n)},i,null,n,1,-1);if(-2===r)return l=String(n),null==d.sub[l]&&(d.sub[l]=o(function(r,t){return r[1]=-1===r[2]?h(r[1],r[0]):_(r[1],r[0]),r[2]=-r[2],t>1&&n>=t&&(r[0]=v(r[0],t)),t>n?r[1]:r},[c,f,1],null,0,n+1)),d.sub[l];if(en(r)){if(1===r.length)return d(n,r[0]);if(l=String(n)+"@"+r.join(","),null==d.nom[l]){for(t=d(r[0]),u=r.length,i=c,e=1;u>e;e++)i=v(i,d(r[e]));d.nom[l]=m(t,i)}return d.nom[l]}if(+r===r){if(r>n-r&&(r=n-r),0>r||1>n)return f;if(0===r||1===n)return c;if(1===r)return s(n);if(l=String(n)+"@"+String(r),null==d.nom[l]){for(n-=r,i=s(1+n),e=2;r>=e;e++)i=v(i,1+n/e);d.nom[l]=a.round(i)}return d.nom[l]}return f}function _(n,r,t){var e=K.Arithmetic,i=e.O,u=e.I;if(t===n&&1===r||r===n&&1===t)return u;if(t+r>n+1||n>r*t)return i;var o,l,a=K.Math,f=e.add,c=a.min(t,n-t-r+2),s=a.max(1,a.ceil((n-t)/(r-1))),d=i;for(o=s;c>=o;o++)l=String(n-t)+","+String(r-1)+","+String(o),null==_.tbl[l]&&(_.tbl[l]=_(n-t,r-1,o)),d=f(d,_.tbl[l]);return l=String(n)+","+String(r)+","+String(t),null==_.tbl[l]&&(_.tbl[l]=d),d}function h(n,r,t){t=-1===t?1:0;for(var e=0,i=0,u=n.length,o=r.length,l=new Array(K.Math.min(u,o)),a=0;u>e&&o>i;)n[e]r[i]?t?e++:i++:(l[a++]=n[e],e++,i++);return a=n||0>=l)return t||[];for(t=t||new Array(l),e=0,i=0,u=0;l>u&&n>e;)(i>=o||e!==r[i])&&(t[u++]=e),e++,i++;return t}function v(n,r,t,e,i,u,o,l,a,f){a=!1!==a,l=-1===l?1:0,null==t&&(t=0),null==e&&(e=n.length-1),null==i&&(i=0),null==u&&(u=r.length-1);var c,s=t,d=i,_=e-t+1,h=u-i+1,m=0,v=_+h,p=!a;for(o=o||new Array(v);e>=s&&u>=d;){if(a&&m){if(n[s]===c){s++;continue}if(r[d]===c){d++;continue}}n[s]r[d]?o[m++]=c=l?n[s++]:r[d++]:(o[m++]=c=n[s],p&&(o[m++]=r[d]),s++,d++)}for(;e>=s;)(p||n[s]!==c)&&(o[m++]=c=n[s]),s++;for(;u>=d;)(p||r[d]!==c)&&(o[m++]=c=r[d]),d++;if(!0===f){for(m=0;v>m;m++)n[t+m]=o[m];return n}return m=r)return n;for(var t,e,i=r,u=1,o=2,l=K.Math.min,a=new Array(r);i;){for(e=r-u,t=0;e>t;t+=o)v(n,n,t,t+u-1,t+u,l(t+o-1,r-1),a,!1,!1,!0);u<<=1,o<<=1,i>>=1}return n}function g(n,r,t,e){var i,u,o,l,a,f=K.Math.rndInt;if(l=!0===t?n.slice():n,a=!0===r?1:0,e)for(i=e.length;ao;o++)u[o]=n[f(0,c)];return e&&p(u),u}for(o=0;r>o;o++)l=f(0,--c),a=n[l],n[l]=n[c],n[c]=a,u[o]=a,i&&(i[o]=l);if(i)for(o=r-1;o>=0;o--)l=i[o],a=n[c],n[c]=n[l],n[l]=a,c++;return e&&p(u),u}function A(n){if(null==n)return null;var r,t,e,i=n.length,u=n[0],o=new Array(u);for(r=0;u>r;r++)o[r]=1;for(t=1;i>t;t++)for(r=0,e=n[t];u>r&&e>0;)o[r++]++,e--;return o}function x(n){var r,t=[],e=n.length,i=n[0],u=[i,1];for(r=1;e>r;r++)i===n[r]?u[1]++:(t.push(u),i=n[r],u=[i,1]);return t.push(u),t}function w(n){var r,t,e,i,u,o=[],l=n.length;for(r=0;l>r;r++)if(u=n[r],1===u[1])o.push(u[0]);else for(e=u[1],i=u[0],t=0;e>t;t++)o.push(i);return o}function b(n){var r,t,e,i,u=n.length,o=new Array(u),l=K.Math.ceil(on(u)),a=(1<<1+l)-1,f=new Array(a),c=1<r;r++)f[r]=0;for(r=0;u>r;r++){for(i=n[r],e=c+i,t=0;l>t;t++)1&e&&(i-=f[e>>>1<<1]),f[e]+=1,e>>>=1;f[e]+=1,o[r]=i}return o}function M(n){var r,t,e,i,u,o,l,a,f,c=n.length,s=new Array(c);for(o=K.Math.ceil(on(c)),l=(1<<1+o)-1,a=new Array(l),f=1<=r;r++)for(t=1,e=1<=t;t++)a[e-1+t]=1<r;r++){for(i=n[r],u=1,t=0;o>t;t++)a[u]-=1,u<<=1,i>=a[u]&&(i-=a[u],u++);a[u]=0,s[r]=u-f}return s}function I(n,r,t){var e,i=n.length,u=null==r;if(i>1)for(u&&(r=new Array(i-1),t=0),e=i-1;e>=1;e--)r[t++]=[n[0],n[e]];else u&&(r=[]);return u?r:t}function E(n,r){var t,e,i,u,o=n.length,l=new Array(o),a=!0===r?1:0,f=new Array(o),c=0,s=0;for(t=0;o>t;t++)f[t]=0;for(i=new Array(o),u=0,e=c++,i[u++]=e,f[e]=1;o>c;){if(e=n[e],f[e])for(u>a&&(i.length=u,l[s++]=i),i=new Array(o),u=0;o>c&&f[e=c];)++c;f[e]||(i[u++]=e,f[e]=1)}return u>a&&(i.length=u,l[s++]=i),sr;r++)u=I(o[r],i,u);return ut;t++)o[t]=t;for(t=0;u>t;t++)swap=e[t],i=o[e[0]],o[e[0]]=o[e[1]],o[e[1]]=i;return o}function R(n,r){var t,e,i=n.length,u=new Array(i);for(t=0;i>t;t++)for(u[t]=new Array(i),e=0;i>e;e++)u[t][e]=0;if(!0===r)for(t=0;i>t;t++)u[n[t]][t]=1;else for(t=0;i>t;t++)u[t][n[t]]=1;return u}function S(n,r){var t,e,i=n.length,u=new Array(i);if(!0===r)for(t=0;i>t;t++)for(e=0;i>e;e++)n[t][e]&&(u[e]=t);else for(t=0;i>t;t++)for(e=0;i>e;e++)n[t][e]&&(u[t]=e);return u}function k(n){var r,t=n.length,e=new Array(t);for(r=0;t>r;r++)e[n[r]]=r;return e}function T(n,r){if(r=r||n.length,r!==n.length)return!1;var t,e,i=new Array(r);for(t=0;r>t;t++)i[t]=0;for(t=0;r>t;t++){if(e=n[t],0>e||e>=r||0!==i[e])return!1;i[e]++}for(t=0;r>t;t++)if(1!==i[t])return!1;return!0}function $(n){var r,t,e,i=n,u=i.length,o=u?i[0]:[],l=o.length;for(t=1;u>t;t++)for(e=o.slice(),r=0;l>r;r++)o[r]=e[i[t][r]];return o}function P(n){var r,t,e,i,u,o,l=n,a=l.length,f=0;for(e=0;a>e;e++)f+=l[e].length;for(r=new Array(f),i=0,e=0;a>e;e++){for(u=l[e],o=u.length,t=0;o>t;t++)r[i+t]=i+u[t];i+=o}return r}function L(n){for(var r=n.length,t=0;r>t;t++)if(n[t]!==t)return!1;return!0}function N(n,r){r=r||1;var t,e=new Array(r+1);for(t=0;r>=t;t++)e[t]=n;return L($(e))}function X(n,r,t){r=0|r;for(var e=0,i=n.length,u=0;i>u;u++)if(n[u]===u&&e++,e>r)return!1;return!0===t?e===r:!0}function j(n,r,t){if(n){var e,i,u,o,l,a=r,f=n.slice();if(0>t){for(e=a-2;e>=0&&n[e]<=n[e+1];)e--;if(e>=0){for(i=a-1;i>e&&n[e]<=n[i];)i--;for(l=f[e],f[e]=f[i],f[i]=l,u=e+1,o=a-1;o>u;)l=f[u],f[u++]=f[o],f[o--]=l}else f=null}else{for(e=a-2;e>=0&&n[e]>=n[e+1];)e--;if(e>=0){for(i=a-1;i>e&&n[e]>=n[i];)i--;for(l=f[e],f[e]=f[i],f[i]=l,u=e+1,o=a-1;o>u;)l=f[u],f[u++]=f[o],f[o--]=l}else f=null}return f}return null}function q(n,r,t,e){if(n){var i,u,o,l,a=r[1],f=r[0],c=e?0:1,s=n.slice();if(0>t){for(i=a-1,u=-1;i>0;){if(s[i]>s[i-1]+c){u=i;break}i--}if(-1===u&&0-1){for(l=f-1+c,i=a-1;i>u;i--)l-=c,s[i]=l;s[u]--}else s=null}else{if(i=a-1,u=-1,e)for(;i>=0;){if(s[i]=0;){if(s[i]-1)for(l=s[u]+1-c,i=u;a>i;i++)l+=c,s[i]=l;else s=null}return s}return null}function V(n,r,t){if(n){var e,i,u=n.slice(),o=r,l=o.length;if(0>t){for(e=l-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;l>i;i++)u[i]=o[i]-1;else u=null}else{for(e=l-1;e>=0&&u[e]+1===o[e];)e--;if(e>=0)for(u[e]++,i=e+1;l>i;i++)u[i]=0;else u=null}return u}return null}function D(n,r,t){if(n){var e,i,u=n.slice(),o=r[0],l=r[1];if(0>t){for(e=o-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,l--,i=e+1;o>i;i++)u[i]=l;else u=null}else{for(e=o-1;e>=0&&u[e]+1===l;)e--;if(e>=0)for(u[e]++,i=e+1;o>i;i++)u[i]=0;else u=null}return u}return null}function J(n,r,t,e,i){if(n){var u,o,l,a,f,c,s,d=r,_=n.slice();if(0>t)if(e)if(l=i?i:Math.ceil(d/e),_[0]>l){for(o=1,c=0;e>o&&_[o]+1>=_[0];)o++;for(_[o]++,u=1;o>u;u++)_[u]=_[o],c+=_[u];for(u=o;e>u;u++)c+=_[u];_[0]=d-c}else _=null;else if(l=i?i+1:1,_[0]>l){for(o=_.length,u=o-1;u>=0&&1===_[u];)u--;for(a=_[u]-1,_=_.slice(0,u+1),_[u]=a,c=0,u=0,o=_.length;o>u;u++)c+=_[u];for(s=d-c;s>0;)f=s,f>a?(f=a,_.push(f)):_.push(s),s-=f}else _=null;else if(e)if(l=i?i:d-e+1,_[0]0&&1===_[o];)o--;for(u=o;u>0&&_[u-1]===_[o];)u--;u===o&&(u=0),_[o]--,_[u]++}else _=null;else if(l=i?i:d,_[0]0&&u--;u>0&&_[u]===_[u-1];)u--;for(_[u]++,_=_.slice(0,u+1),c=0,u=0,o=_.length;o>u;u++)c+=_[u];for(s=d-c;s>0;)_.push(1),s--}else _=null;return _}return null}var G,H,F,U,B,Y,z,K={VERSION:"0.5.1"},Q="prototype",W="constructor",Z=Array.prototype.slice,nn=Object[Q].hasOwnProperty,rn=Object[Q].toString,tn=/^\s+|\s+$/g,en=(String.prototype.trim?function(n){return n.trim()}:function(n){return n.replace(tn,"")},function(n){return n instanceof Array||"[object Array]"===rn.call(n)}),un=function(n){return n instanceof String||"[object String]"===rn.call(n)},on=Math.log2||function(n){return Math.log(n)/Math.LN2},ln=function(n){var r=n.toString(2),t=32-r.length;return t>0?new Array(t+1).join("0")+r:r},an=Object.create,fn=function(n,r){for(var t in r)nn.call(r,t)&&(n[t]=r[t]);return n},cn=function(n,r){1===arguments.length&&(r=n,n=Object);var t=r[W];return nn.call(r,"__static__")&&(t=fn(t,r.__static__),delete r.__static__),t[Q]=fn(an(n[Q]),r),t},sn=1,dn=2,_n=4,hn=8,mn=16,vn=32,pn=_n|hn|mn,gn=pn|vn|sn|dn;return d.fac={},d.sub={},d.nom={},_.tbl={},K.ORDER={LEX:_n,LEXICOGRAPHIC:_n,REVLEX:_n|sn,ANTILEX:_n|sn,REVERSELEXICOGRAPHIC:_n|sn,ANTILEXICOGRAPHIC:_n|sn,REFLEX:_n|dn,REFLECTEDLEXICOGRAPHIC:_n|dn,COLEX:hn,COLEXICOGRAPHIC:hn,REVCOLEX:hn|sn,ANTICOLEX:hn|sn,REVERSECOLEXICOGRAPHIC:hn|sn,ANTICOLEXICOGRAPHIC:hn|sn,REFCOLEX:hn|dn,REFLECTEDCOLEXICOGRAPHIC:hn|dn,REV:sn,REVERSE:sn,REVERSED:sn,REF:dn,REFLECT:dn,REFLECTED:dn,RANDOM:vn},K.Util={intersect:h,merge:v,complement:m,conjugation:e,parity:i,inversion:u,mergesort:p,shuffle:g,pick:y},K.Math={O:0,I:1,J:-1,N:function(n){return K.Arithmetic.add(K.Arithmetic.O,n)},V:function(n){return K.Arithmetic.sub(K.Arithmetic.O,n)},rnd:Math.random,rndInt:function(n,r){return K.Math.round((r-n)*K.Math.rnd()+n)},equ:function(n,r){return n===r},gte:function(n,r){return n>=r},lte:function(n,r){return r>=n},gt:function(n,r){return n>r},lt:function(n,r){return r>n},inside:function(n,r,t,e){return e?n>=r&&t>=n:n>r&&t>n},clamp:function(n,r,t){return r>n?r:n>t?t:n},wrap:function(n,r,t){return r>n?t:n>t?r:n},wrapR:function(n,r){return 0>n?n+r:n},add:function(n,r){return n+r},sub:function(n,r){return n-r},mul:function(n,r){return n*r},div:function(n,r){return K.Math.floor(n/r)},mod:function(n,r){return n%r},pow:Math.pow,shl:function(n,r){return n<>r},bor:function(n,r){return n|r},band:function(n,r){return n&r},xor:function(n,r){return n^r},abs:Math.abs,min:Math.min,max:Math.max,floor:Math.floor,ceil:Math.ceil,round:Math.round,num:function(n){return"number"==typeof n?K.Math.floor(n):parseInt(n,10)},val:function(n){return K.Math.floor(n.valueOf())},sum:a,product:f,pow2:c,exp:s,factorial:d,partitions:_},K.Arithmetic={O:0,I:1,J:-1,N:K.Math.N,V:K.Math.V,equ:K.Math.equ,gte:K.Math.gte,lte:K.Math.lte,gt:K.Math.gt,lt:K.Math.lt,inside:K.Math.inside,clamp:K.Math.clamp,wrap:K.Math.wrap,wrapR:K.Math.wrapR,add:K.Math.add,sub:K.Math.sub,mul:K.Math.mul,div:K.Math.div,mod:K.Math.mod,pow:K.Math.pow,shl:K.Math.shl,shr:K.Math.shr,bor:K.Math.bor,band:K.Math.band,xor:K.Math.xor,abs:K.Math.abs,min:K.Math.min,max:K.Math.max,floor:K.Math.floor,ceil:K.Math.ceil,round:K.Math.round,rnd:K.Math.rndInt,num:K.Math.num,val:K.Math.val},K.Class=cn,K.BitArray=cn({constructor:function yn(n){var r=this;return r instanceof yn?(r.length=n,void(r.bits=new Uint32Array(K.Math.ceil(n/32)))):new yn(n)},length:0,bits:null,dispose:function(){var n=this;return n.length=null,n.bits=null,n},clone:function(){var n=this,r=new K.BitArray(n.length);return r.bits=new Uint32Array(n.bits),r},fromArray:function(n){var r=this;return r.bits=new Uint32Array(n),r},toArray:function(){return Z.call(this.bits)},toString:function(){var n,r,t=this.toArray();for(n=0,r=t.length;r>n;n++)t[n]=ln(t[n]);return t.join("")},reset:function(){var n,r=this,t=r.bits,e=t.length;for(n=0;e>n;n++)t[n]=0;return r},isset:function(n){return!!(this.bits[n>>>5]&1<<(31&n))},set:function(n){var r=this;return r.bits[n>>>5]|=1<<(31&n),r},unset:function(n){var r=this;return r.bits[n>>>5]&=~(1<<(31&n)),r},toggle:function(n){var r=this;return r.bits[n>>>5]^=1<<(31&n),r}}),G=K.CombinatorialIterator=cn({constructor:function(n,r){var t=this,e=t[W];t.n=n||0,t.$=r=r||{},r.type=String(r.type||"combinatorial").toLowerCase(),r.order=r.order||_n,r.count=e.count(t.n,t.$),t.order(r.order)},__static__:{Iterable:function An(n){var r=this;return r instanceof An?void(r.next=function(){return n.hasNext()?{value:n.next()}:{done:!0}}):new An(n)},C:function(n,r){return e(n,r)},P:function(n,r){return i(n)},T:function(n,r){return u(n,r)},count:r,initial:r,rank:r,unrank:r,dual:function(n,r,t,e){if(null==n)return null;var i=this,u=e&&e.order?e.order:0,o=i.C,l=i.P;i.T;return vn&u?dn&u?l(n,t):n:hn&u?dn&u?o(n,t):l(o(n,t),t):dn&u?l(n,t):n.slice()},succ:function(n,r,t,e,i){var u=this,o=K.Arithmetic;return null==r?null:u.unrank(o.add(t,0>n?o.J:o.I),e,i)},rand:function(n,r){var t=this,e=K.Arithmetic,i=r&&r.count?r.count:t.count(n,r);return t.unrank(e.rnd(e.O,e.sub(i,e.I)),n,r)}},n:0,m:null,i:null,$:null,__index:null,_index:null,__item:null,_item:null,_prev:null,_next:null,_traversed:null,dispose:function(){var n=this;return n.n=null,n.m=null,n.i=null,n.$=null,n.__index=null,n._index=null,n.__item=null,n._item=null,n._prev=null,n._next=null,n._traversed&&(n._traversed.dispose(),n._traversed=null),n},_store:function(){var n=this;return[n.n,n.m,n.i,n.$.order,n.__index,n._index,n.__item,n._item,n._prev,n._next]},_restore:function(n){var r=this;return n&&(r.n=n[0],r.m=n[1],r.i=n[2],r.$.order=n[3],r.__index=n[4],r._index=n[5],r.__item=n[6],r._item=n[7],r._prev=n[8],r._next=n[9]),r},total:function(){return this.$.count||0},order:function(n,r){if(!arguments.length)return this._order;var e,i,u,o,l,a,f=this,c=K.Arithmetic,s=c.O,d=c.I,_=f[W];_.T;return r=-1===r,n=t(n),o=f.n,l=f.$,i=l.count,u=c.sub(i,d),a=sn&n?-1:1,a=r?-a:a,l.order=n,f.__index=f._index=s,f._item=f.__item=null,f._prev=!1,f._next=!1,vn&n?(c.gt(i,1e6)?(f._traversed&&(f._traversed.dispose(),f._traversed=null),e=f.randomIndex()):(f._traversed?f._traversed.reset():f._traversed=new K.BitArray(i),f._traversed.set(e=f.randomIndex())),f.__item=_.unrank(e,o,l),null!=f.__item&&(f.__index=e)):hn&n?(f.__item=_.initial(-a,o,l),null!=f.__item&&(f.__index=-1===a?s:u)):(f.__item=_.initial(a,o,l),null!=f.__item&&(f.__index=-1===a?u:s)),f._item=null==f.__item?null:_.dual(f.__item,f.__index,o,l),f._index=!r||vn&n?s:u,f._prev=vn&n||!r?!1:null!=f.__item,f._next=!r||vn&n?null!=f.__item:!1,f},index:function(n){if(!arguments.length)return this._index;var r,t=this,e=K.Arithmetic,i=e.O,u=e.I,o=e.J,l=t[W],a=(l.T,t.n),f=t.$,c=f.count,s=f.order,d=sn&s?-1:1;return n=e.wrapR(e.N(n),c),!e.equ(n,t._index)&&e.inside(n,o,c)&&(r=e.sub(c,u),hn&s?(t.__index=-1===d?n:e.sub(r,n),t._index=n,t.__item=e.equ(i,n)?l.initial(-d,a,f):e.equ(r,n)?l.initial(d,a,f):l.unrank(t.__index,a,f),t._item=l.dual(t.__item,t.__index,a,f),t._prev=null!=t.__item,t._next=null!=t.__item):vn&s||(t.__index=-1===d?e.sub(r,n):n,t._index=n,t.__item=e.equ(i,n)?l.initial(d,a,f):e.equ(r,n)?l.initial(-d,a,f):l.unrank(t.__index,a,f),t._item=l.dual(t.__item,t.__index,a,f),t._prev=null!=t.__item,t._next=null!=t.__item)),t},item:function(n,r){if(!arguments.length)return this._item;var e,i,u,o,l,a=this,f=a.n,c=a.$,s=c.count,d=a[W],_=(d.T,K.Arithmetic),h=_.O,m=_.I,v=_.J;return r=null!=r?t(r):c.order,n=_.wrapR(_.N(n),s),r===c.order&&_.equ(n,a._index)?a._item:_.inside(n,v,s)?(i=sn&r?-1:1,e=_.sub(s,m),vn&r?(u=a.randomIndex(),o=c.order,c.order=r,l=d.dual(d.unrank(u,f,c),u,f,c),c.order=o,l):hn&r?(u=-1===i?n:_.sub(e,n),o=c.order,c.order=r,l=d.dual(_.equ(h,n)?d.initial(-i,f,c):_.equ(e,n)?d.initial(i,f,c):d.unrank(u,f,c),u,f,c),c.order=o,l):(u=-1===i?_.sub(e,n):n,o=c.order,c.order=r,l=d.dual(_.equ(h,n)?d.initial(i,f,c):_.equ(e,n)?d.initial(-i,f,c):d.unrank(u,f,c),u,f,c),c.order=o,l)):null},randomIndex:function(n,r){var t=this,e=K.Arithmetic,i=e.N,u=e.O,o=e.I,l=t.$.count,a=arguments.length;return 0===a?(n=u,r=e.sub(l,o)):1===a?(n=i(n||0),r=e.sub(l,o)):(n=i(n),r=i(r)),e.rnd(n,r)},random:function(){var n,r=this,t=r[W],e=r.$.order;return r.$.order|=vn,n=t.rand(r.n,r.$),r.$.order=e,n=t.dual(n,null,r.n,r.$)},rewind:function(n){var r=this;return r.order(r.$.order,-1===n?-1:1)},hasNext:function(n){var r=this;return-1===n?vn&r.$.order?!1:r._prev:r._next},next:function(n){var r,t,n,e,i,u=this,o=K.Arithmetic,l=o.O,a=o.I,f=o.J,c=u[W],s=(c.T,u._item),d=u.n,_=u.$,h=_.order,m=_.count;if(-1===n)return vn&h?null:(n=sn&h?-1:1,hn&h?(u.__item=c.succ(n,u.__item,u.__index,d,_),null!=u.__item&&(u.__index=o.add(u.__index,0>n?f:a))):(u.__item=c.succ(-n,u.__item,u.__index,d,_),null!=u.__item&&(u.__index=o.add(u.__index,n>0?f:a))),u._item=null==u.__item?null:c.dual(u.__item,u.__index,d,_),u._prev=null!=u.__item,u._prev&&(u._index=o.sub(u._index,a)),s);if(vn&h)if(e=o.sub(m,a),o.lt(u._index,e))if(r=u._traversed){for(t=u.randomIndex(),i=K.Math.rnd()>.5?f:a;r.isset(t);)t=o.wrap(o.add(t,i),l,e);r.set(t),u.__item=c.unrank(t,d,_),null!=u.__item&&(u.__index=t)}else t=u.randomIndex(),u.__item=c.unrank(t,d,_),null!=u.__item&&(u.__index=t);else u._item=u.__item=null,u._traversed&&(u._traversed.dispose(),u._traversed=null);else n=sn&h?-1:1,hn&h?(u.__item=c.succ(-n,u.__item,u.__index,d,_),null!=u.__item&&(u.__index=o.add(u.__index,n>0?f:a))):(u.__item=c.succ(n,u.__item,u.__index,d,_),null!=u.__item&&(u.__index=o.add(u.__index,0>n?f:a)));return u._item=null==u.__item?null:c.dual(u.__item,u.__index,d,_),u._next=null!=u.__item,u._next&&(u._index=o.add(u._index,a)),s},range:function(n,r){var t,e,i,u,o,l=this,a=K.Arithmetic,f=a.N,c=a.O,s=a.I,d=l.$,_=d.count,h=1,m=arguments.length,v=a.sub(_,s),p=!(vn&d.order);if(1>m?(n=c,r=v):2>m?(n=f(n),r=v):(n=f(n),r=f(r)),n=a.wrapR(n,_),r=a.wrapR(r,_),a.gt(n,r)&&(t=n,n=r,r=t,h=-1),n=a.clamp(n,c,v),p&&(r=a.clamp(r,c,v)),a.lte(n,r)){if(o=l._store(),p&&l.index(n),i=a.val(a.sub(r,n)),e=new Array(i+1),0>h)for(u=i;u>=0;u--)e[u]=l.next();else for(u=0;i>=u;u++)e[u]=l.next();l._restore(o)}else e=[];return e},__iter__:function(){return new G.Iterable(this)}}),"undefined"!=typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(G[Q][Symbol.iterator]=G[Q].__iter__),H=K.Permutation=cn(G,{constructor:function xn(n,r){var t=this;return t instanceof xn?(r=r||{},r.type="permutation",void G.call(t,n||1,r)):new xn(n,r)},__static__:{C:function(n,r){return e(n,-1)},P:G.P,T:G.T,count:function(n,r){return K.Math.factorial(n)},initial:function(n,r,t){var e,i=new Array(r);if(0>n)for(r-=1,e=0;r>=e;e++)i[e]=r-e;else for(e=0;r>e;e++)i[e]=e;return i},dual:G.dual,succ:function(n,r,t,e,i){return j(r,e,n)},rand:function(n,r){var t,e;K.Math.rndInt;for(e=new Array(n),t=0;n>t;t++)e[t]=t;return g(e,!(!r||!r.cyclic),!1),e},rank:function(n,r,t){var e,i,u,o=K.Arithmetic;if(r=r||n.length,!r)return o.J;for(n=b(n),e=o.O,u=r-1,i=0;u>i;i++)e=o.add(o.mul(e,r-i),n[i]);return e},unrank:function(n,r,t){var e,i,u,o,l,a=K.Arithmetic;if(!r)return[];for(e=new Array(r),e[r-1]=0,i=n,u=r-2;u>=0;u--)o=r-u,l=a.mod(i,o),i=a.div(i,o),e[u]=a.val(l);return M(e)},permute:function(n,r,t){var e,i,u,o=n.length;for(!0===t?(i=new Array(o),u=n):(i=n,u=n.slice()),e=0;o>e;e++)i[e]=u[r[e]];return i},shuffle:function(n,r){return g(n,!0===r,!1)},compose:function(){return $(arguments)},concatenate:function(){return P(arguments)},inverse:function(n){return k(n)},cycles:function(n,r){return-1===r?cycles2permutation(n):E(n)},swaps:function(n,r){return-1===r?C(n):O(n)},inversion:function(n,r){return-1===r?M(n):b(n)},matrix:function(n,r,t){return-1===t?S(n,r):R(n,r)},parity:r,is_permutation:T,is_identity:L,is_derangement:X,is_involution:function(n){return N(n,1)},is_kthroot:function(n,r){return r>1?N(n,r-1):!1},is_connected:function(n){var r,t=n.length,e=-1;for(r=0;t-1>r;r++)if(n[r]>e&&(e=n[r]),r>=e)return!1;return!0}}}),F=K.Combination=cn(G,{constructor:function wn(n,r,t){var e=this;return e instanceof wn?(t=t||{},t.type=t.type||"combination",void G.call(e,[n||1,r||1],t)):new wn(n,r,t)},__static__:{C:function(n,r){return e(n,r[0])},P:G.P,T:G.T,count:function(n,r){return K.Math.factorial(r&&"repeated"===r.type?n[0]+n[1]-1:n[0],n[1])},initial:function(n,r,t){var e,i=t&&"repeated"===t.type,u=r[1]-1,o=new Array(u+1);if(0>n)if(r=r[0]-1,i)for(e=0;u>=e;e++)o[e]=r;else for(e=0;u>=e;e++)o[u-e]=r-e;else if(i)for(e=0;u>=e;e++)o[e]=0;else for(e=0;u>=e;e++)o[e]=e;return o},dual:G.dual,succ:function(n,r,t,e,i){return q(r,e,n,i&&"repeated"===i.type)},rand:function(n,r){var t,e,i,u,o=n[1],l=K.Math.rndInt,a=r&&"repeated"===r.type;if(n=n[0],i=n-o,u=n-1,a)if(1===o)t=[l(0,u)];else{for(t=new Array(o),e=0;o>e;e++)t[e]=l(0,u);p(t)}else{var f,c,s;if(1===o)t=[l(0,u)];else if(n===o)for(t=new Array(o),e=0;o>e;e++)t[e]=e;else if(o>i){for(f={},s=new Array(i),e=0;i>e;e++){do c=l(0,u);while(1===f[c]);f[c]=1,s[e]=c}t=m(n,p(s))}else{for(f={},t=new Array(o),e=0;o>e;e++){do c=l(0,u);while(1===f[c]);f[c]=1,t[e]=c}p(t)}}return t},rank:function(n,r,t){var e,i,u,o,l,a=K.Arithmetic,f=a.add,c=a.sub,s=a.O,d=r[1],_=t&&"repeated"===t.type,h=K.Math.factorial;if(r=r[0],o=_?r+d-1:r,l=t&&t.count?t.count:h(o,d),_)for(e=1;d>=e;e++)i=o-1-n[e-1]-e+1,u=d+1-e,i>=u&&(s=f(s,h(i,u)));else for(e=1;d>=e;e++)i=o-1-n[e-1],u=d+1-e,i>=u&&(s=f(s,h(i,u)));return c(c(l,a.I),s)},unrank:function(n,r,t){var e,i,u,o,l,a,f=K.Arithmetic,c=f.O,s=f.I,d=r[1],_=t&&"repeated"===t.type;r=r[0],u=_?r+d-1:r,i=t&&t.count?t.count:K.Math.factorial(u,d),e=new Array(d),n=f.sub(f.sub(i,s),n),i=f.div(f.mul(i,u-d),u),l=u-d+1,o=d,a=u-1;do f.lte(i,n)?(e[d-o]=_?u-l-d+1:u-l-o+1,f.gt(i,c)&&(n=f.sub(n,i),i=f.div(f.mul(i,o),a)),o--,a--):(i=f.div(f.mul(i,a-o),a),l--,a--);while(o>0);return e},complement:function(n,r){return m(r,n)},pick:function(n,r,t,e){return y(n,r,!1===t,!0===e,new Array(r))},choose:function(n,r){var t,e=r.length,i=new Array(e);for(t=0;e>t;t++)i[t]=n[r[t]];return i}}}),F.conjugate=F.complement,B=K.Powerset=K.Subset=cn(G,{constructor:function bn(n,r){var t=this;return t instanceof bn?(r=r||{},r.type="subset",void G.call(t,n||1,r)):new bn(n,r)},__static__:{C:function(n,r){return m(r,n)},P:G.P,T:G.T,count:function(n,r){return K.Math.pow2(n)},initial:function(n,r,t){var e,i;if(0>n)for(e=new Array(r),i=0;r>i;i++)e[i]=i;else e=[];return e},dual:function(n,r,t,e){if(null==n)return null;var i=this,u=e&&e.order?e.order:0,o=i.C,l=i.P;i.T;return vn&u?dn&u?n:l(n,t):hn&u?dn&u?l(o(n,t),t):o(n,t):dn&u?n.slice():l(n,t)},succ:G.succ,rand:G.rand,rank:function(n,r,t){for(var e=K.Arithmetic,i=e.O,u=e.I,o=i,l=0,a=subset.length;a>l;)o=e.add(o,e.shl(u,subset[l++]));return o},unrank:function(n,r,t){var e=this,i=K.Arithmetic,u=i.O,o=[],l=0;if(!i.inside(n,i.J,t&&t.count?t.count:e.count(r,t)))return null;for(;i.gt(n,u);)i.gt(i.band(n,1),u)&&o.push(l),i.gt(i.band(n,2),u)&&o.push(l+1),i.gt(i.band(n,4),u)&&o.push(l+2),i.gt(i.band(n,8),u)&&o.push(l+3),i.gt(i.band(n,16),u)&&o.push(l+4),i.gt(i.band(n,32),u)&&o.push(l+5),i.gt(i.band(n,64),u)&&o.push(l+6),i.gt(i.band(n,128),u)&&o.push(l+7),l+=8,n=i.shr(n,8);return o}}}),U=K.Partition=cn(G,{constructor:function Mn(n,r){var t=this;return t instanceof Mn?(r=r||{},r.type="partition",void G.call(t,n||1,r)):new Mn(n,r)},__static__:{C:function(n,r){return A(n)},P:G.P,T:G.T,count:function(n,r){var t,e,i=K.Arithmetic.add,u=K.Math.partitions,o=K.Arithmetic.O,l=r&&r.max?0|r.max:null,a=r&&r.exactly?0|r.exactly:null;if(0>n||l&&l>n||a&&a>n)return o;if(a)for(e=l?l:n-a+1;e>=1;e--)o=i(o,u(n,a,e));else if(l)for(e=n-l+1;e>=1;e--)o=i(o,u(n,l,e));else for(t=1;n>=t;t++)for(e=n-t+1;e>=1;e--)o=i(o,u(n,t,e));return o},initial:function(n,r,t){var e,i,u,o,l=t&&t.max?0|t.max:null,a=t&&t.exactly?0|t.exactly:null;if(0>r||a&&a>r||l&&l>r)return null;if(a)if(o=new Array(a),0>n)for(o[0]=r-a+1,e=1;a>e;e++)o[e]=1;else for(o[0]=i=Math.ceil(r/a),o[a-1]=Math.floor(r/a),u=a-1,e=1;u>e;e++)o[e]=i;else if(l)if(a=l,o=new Array(a),0>n)for(o[0]=i=Math.ceil(r/a),o[a-1]=Math.floor(r/a),u=a-1,e=1;u>e;e++)o[e]=i;else for(o[0]=r-a+1,e=1;a>e;e++)o[e]=1;else if(0>n)o=[r];else for(o=new Array(r),e=0;r>e;e++)o[e]=1;return o},dual:function(n,r,t,e){var i=e&&e.max?0|e.max:null,u=e&&e.exactly?0|e.exactly:null;return null==n?null:i&&!u?A(n):n.slice()},succ:function(n,r,t,e,i){var u=i&&i.max?0|i.max:null,o=i&&i.exactly?0|i.exactly:null;return 0>e||o&&o>e||u&&u>e?null:J(r,e,u&&!o?-n:n,o?o:u&&!o?u:null)},rand:G.rand,rank:r,unrank:r,conjugate:A,pack:x,unpack:w}}),U.transpose=U.conjugate,Y=K.Tensor=cn(G,{constructor:function In(){var n=this,r=arguments;return n instanceof In?void(r.length?G.call(n,r[0]instanceof Array?r[0]:Z.call(r),{type:"tensor"}):(n.n=[],n.$={type:"tensor",count:0,order:_n})):(n=new In,r.length?G.call(n,r[0]instanceof Array?r[0]:Z.call(r),{type:"tensor"}):(n.n=[],n.$={type:"tensor",count:0,order:_n}),n)},__static__:{C:G.C,P:G.P,T:G.T,count:function(n,r){return n&&n.length?K.Math.product(n):0},initial:function(n,r,t){var e,i=r.length,u=new Array(i);if(0>n)for(e=0;i>e;e++)u[e]=r[e]-1;else for(e=0;i>e;e++)u[e]=0;return u},dual:G.dual,succ:function(n,r,t,e,i){return V(r,e,n)},rand:function(n,r){var t,e=K.Math.rndInt,i=n.length,u=new Array(i);for(t=0;i>t;t++)u[t]=e(0,n[t]-1);return u},rank:function(n,r,t){var e,i,u=K.Arithmetic,o=r.length;if(!o)return u.J;for(e=u.O,i=0;o>i;i++)e=u.add(u.mul(e,r[i]),n[i]);return e},unrank:function(n,r,t){var e,i,u,o,l,a=K.Arithmetic,f=r.length;if(!f)return[];for(l=new Array(f),e=n,u=f-1;u>=0;u--)i=r[u],o=a.mod(e,i),e=a.div(e,i),l[u]=a.val(o);return l},product:l,component:function(n,r){var t,e,i,u,o,l,a=[],f=r,c=f.length;for(t=0;c>t;t++)if(i=f[t],o=n[t],u=i[o],u instanceof Array)for(e=0,l=u.length;l>e;e++)a.push(u[e]);else a.push(u);return a}}}),z=K.Tuple=cn(G,{constructor:function En(n,r,t){var e=this;return e instanceof En?(t=t||{},t.type="tuple",void G.call(e,[n||1,r||2],t)):new En(n,r,t)},__static__:{C:function(n,r){return e(n,r[1])},P:G.P,T:G.T,count:function(n,r){return K.Math.exp(n[0],n[1])},initial:function(n,r,t){var e,i=r[0],u=new Array(i);if(0>n)for(r=r[1]-1,e=0;i>e;e++)u[e]=r;else for(e=0;i>e;e++)u[e]=0;return u},dual:G.dual,succ:function(n,r,t,e,i){return D(r,e,n)},rand:function(n,r){var t,e=K.Math.rndInt,i=n[0],u=n[1]-1,o=new Array(i);for(t=0;i>t;t++)o[t]=e(0,u);return o},rank:function(n,r,t){var e,i,u=K.Arithmetic,o=r[0],l=r[1];for(e=u.O,i=0;o>i;i++)e=u.add(u.mul(e,l),n[i]);return e},unrank:function(n,r,t){var e,i,u,o,l=K.Arithmetic,a=r[1],f=r[0];for(o=new Array(f),e=n,i=f-1;i>=0;i--)u=l.mod(e,a),e=l.div(e,a),o[i]=l.val(u);return o}}}),K}); \ No newline at end of file diff --git a/test/combinations.js b/test/combinations.js index 2a49778..7dc410c 100644 --- a/test/combinations.js +++ b/test/combinations.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -46,8 +46,8 @@ print_all( o.rewind()/*, 1, function(item){ }*/ ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/combinations.txt b/test/combinations.txt index fbfb6fd..412fbe9 100644 --- a/test/combinations.txt +++ b/test/combinations.txt @@ -1,4 +1,4 @@ -Abacus.Combinations (VERSION = 0.5.0) +Abacus.Combinations (VERSION = 0.5.1) --- o = Abacus.Combination(6,3) o.total() @@ -32,7 +32,7 @@ o.rewind() [ 2, 4, 5 ] [ 3, 4, 5 ] backwards -o.forward() +o.rewind(-1) [ 3, 4, 5 ] [ 2, 4, 5 ] [ 2, 3, 5 ] @@ -159,28 +159,28 @@ o.order("colex,reversed") [ 0, 1, 3 ] [ 0, 1, 2 ] o.order("random") -[ 1, 2, 4 ] -[ 1, 2, 3 ] +[ 1, 3, 4 ] [ 0, 4, 5 ] -[ 0, 3, 5 ] -[ 0, 1, 2 ] -[ 0, 1, 3 ] -[ 2, 3, 4 ] -[ 0, 1, 4 ] -[ 1, 3, 5 ] -[ 0, 1, 5 ] [ 0, 2, 3 ] -[ 0, 3, 4 ] -[ 1, 4, 5 ] [ 0, 2, 5 ] +[ 1, 2, 3 ] +[ 0, 3, 4 ] [ 0, 2, 4 ] +[ 0, 3, 5 ] +[ 0, 1, 5 ] +[ 1, 2, 4 ] +[ 0, 1, 4 ] +[ 2, 3, 4 ] [ 1, 2, 5 ] -[ 3, 4, 5 ] -[ 1, 3, 4 ] -[ 2, 4, 5 ] +[ 0, 1, 3 ] +[ 1, 3, 5 ] +[ 1, 4, 5 ] [ 2, 3, 5 ] -o.random() +[ 2, 4, 5 ] [ 0, 1, 2 ] +[ 3, 4, 5 ] +o.random() +[ 0, 1, 5 ] o.order("colex").range(-5, -1) [ 2, 3, 5 ] [ 0, 4, 5 ] diff --git a/test/combinations_repeats.js b/test/combinations_repeats.js index 4361627..af16169 100644 --- a/test/combinations_repeats.js +++ b/test/combinations_repeats.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -20,8 +20,8 @@ echo('Abacus.CombinationRepeats (VERSION = '+Abacus.VERSION+')'); echo('---'); // CombinationRepeats -echo('o = Abacus.Combination(6,3,"repeated")'); -o = Abacus.Combination(6,3,"repeated"); +echo('o = Abacus.Combination(6,3,{type:"repeated"})'); +o = Abacus.Combination(6,3,{type:"repeated"}); echo('o.total()'); echo(o.total()); @@ -46,8 +46,8 @@ print_all( o.rewind()/*, 1, function(item){ }*/ ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/combinations_repeats.txt b/test/combinations_repeats.txt index 857e079..731046a 100644 --- a/test/combinations_repeats.txt +++ b/test/combinations_repeats.txt @@ -1,6 +1,6 @@ -Abacus.CombinationRepeats (VERSION = 0.5.0) +Abacus.CombinationRepeats (VERSION = 0.5.1) --- -o = Abacus.Combination(6,3,"repeated") +o = Abacus.Combination(6,3,{type:"repeated"}) o.total() 56 o.next() @@ -68,7 +68,7 @@ o.rewind() [ 4, 5, 5 ] [ 5, 5, 5 ] backwards -o.forward() +o.rewind(-1) [ 5, 5, 5 ] [ 4, 5, 5 ] [ 4, 4, 5 ] @@ -411,64 +411,64 @@ o.order("colex,reversed") [ 0, 0, 1 ] [ 0, 0, 0 ] o.order("random") -[ 1, 1, 5 ] -[ 4, 5, 5 ] -[ 2, 3, 4 ] -[ 4, 4, 4 ] +[ 1, 1, 3 ] [ 1, 3, 4 ] -[ 0, 3, 4 ] [ 2, 2, 4 ] +[ 1, 3, 5 ] [ 1, 1, 2 ] [ 1, 2, 4 ] -[ 0, 0, 4 ] -[ 0, 0, 5 ] -[ 2, 2, 5 ] +[ 0, 1, 5 ] +[ 2, 2, 3 ] +[ 1, 2, 3 ] +[ 0, 0, 1 ] +[ 2, 2, 2 ] +[ 0, 1, 4 ] +[ 2, 5, 5 ] +[ 1, 5, 5 ] +[ 4, 4, 4 ] +[ 0, 5, 5 ] +[ 0, 2, 2 ] [ 0, 3, 3 ] -[ 2, 3, 3 ] +[ 0, 2, 3 ] +[ 0, 1, 3 ] +[ 2, 2, 5 ] +[ 1, 4, 4 ] +[ 4, 5, 5 ] [ 4, 4, 5 ] +[ 3, 3, 4 ] +[ 0, 1, 1 ] +[ 0, 0, 3 ] +[ 2, 4, 4 ] +[ 1, 3, 3 ] [ 0, 2, 5 ] +[ 2, 4, 5 ] +[ 0, 0, 5 ] +[ 2, 3, 3 ] +[ 1, 4, 5 ] +[ 2, 3, 4 ] +[ 1, 1, 1 ] +[ 1, 1, 5 ] +[ 2, 3, 5 ] [ 0, 2, 4 ] +[ 0, 1, 2 ] +[ 3, 3, 3 ] +[ 1, 2, 2 ] +[ 1, 2, 5 ] [ 1, 1, 4 ] -[ 3, 3, 5 ] -[ 0, 1, 1 ] -[ 3, 3, 4 ] +[ 0, 4, 5 ] +[ 0, 0, 4 ] +[ 0, 3, 4 ] [ 0, 3, 5 ] -[ 2, 2, 2 ] -[ 3, 3, 3 ] -[ 0, 0, 1 ] +[ 3, 3, 5 ] +[ 0, 4, 4 ] [ 0, 0, 2 ] +[ 3, 4, 4 ] +[ 0, 0, 0 ] [ 5, 5, 5 ] -[ 0, 4, 4 ] -[ 1, 2, 5 ] -[ 0, 1, 2 ] [ 3, 4, 5 ] -[ 1, 2, 3 ] -[ 1, 3, 3 ] -[ 2, 3, 5 ] -[ 2, 5, 5 ] -[ 2, 4, 4 ] -[ 0, 1, 5 ] -[ 1, 1, 3 ] [ 3, 5, 5 ] -[ 0, 2, 2 ] -[ 2, 2, 3 ] -[ 1, 5, 5 ] -[ 1, 1, 1 ] -[ 2, 4, 5 ] -[ 1, 3, 5 ] -[ 0, 4, 5 ] -[ 1, 2, 2 ] -[ 1, 4, 5 ] -[ 0, 2, 3 ] -[ 0, 0, 3 ] -[ 1, 4, 4 ] -[ 3, 4, 4 ] -[ 0, 5, 5 ] -[ 0, 0, 0 ] -[ 0, 1, 4 ] -[ 0, 1, 3 ] o.random() -[ 0, 2, 3 ] +[ 2, 3, 4 ] o.order("colex").range(-5, -1) [ 1, 5, 5 ] [ 2, 5, 5 ] diff --git a/test/partitions.js b/test/partitions.js index 3577fe1..31a810c 100644 --- a/test/partitions.js +++ b/test/partitions.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -20,6 +20,34 @@ echo('Abacus.Partitions (VERSION = '+Abacus.VERSION+')'); echo('---'); // Partitions + +echo('o = Abacus.Partition(7)'); +o = Abacus.Partition(7); + +echo('o.total()'); +echo(o.total()); + +echo('o.next()'); +echo(o.next()); + +echo('o.hasNext()'); +echo(o.hasNext()); +echo('o.next()'); +echo(o.next()); + +echo('default order is "lex", lexicographic-order'); +echo('o.rewind()'); +print_all( o.rewind() ); + +echo('backwards'); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); + +// dispose +echo('o.dispose()'); +o.dispose(); + + echo('o = Abacus.Partition(8)'); o = Abacus.Partition(8); @@ -39,11 +67,85 @@ echo('o.rewind()'); print_all( o.rewind() ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); + +// dispose +echo('o.dispose()'); +o.dispose(); + + +echo('o = Abacus.Partition(7,{max:4})'); +o = Abacus.Partition(7,{max:4}); + +echo('o.total()'); +echo(o.total()); + +echo('default order is "lex", lexicographic-order'); +echo('o.rewind()'); +print_all( o.rewind() ); + +echo('backwards'); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); + +// dispose +echo('o.dispose()'); +o.dispose(); + +echo('o = Abacus.Partition(8,{max:4})'); +o = Abacus.Partition(8,{max:4}); + +echo('o.total()'); +echo(o.total()); + +echo('default order is "lex", lexicographic-order'); +echo('o.rewind()'); +print_all( o.rewind() ); + +echo('backwards'); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); // dispose echo('o.dispose()'); o.dispose(); +echo('o = Abacus.Partition(8,{exactly:4})'); +o = Abacus.Partition(8,{exactly:4}); + +echo('o.total()'); +echo(o.total()); + +echo('default order is "lex", lexicographic-order'); +echo('o.rewind()'); +print_all( o.rewind() ); + +echo('backwards'); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); + +// dispose +echo('o.dispose()'); +o.dispose(); + + +echo('o = Abacus.Partition(7,{exactly:4})'); +o = Abacus.Partition(7,{exactly:4}); + +echo('o.total()'); +echo(o.total()); + +echo('default order is "lex", lexicographic-order'); +echo('o.rewind()'); +print_all( o.rewind() ); + +echo('backwards'); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); + +// dispose +echo('o.dispose()'); +o.dispose(); + diff --git a/test/partitions.txt b/test/partitions.txt index acdac29..4722736 100644 --- a/test/partitions.txt +++ b/test/partitions.txt @@ -1,5 +1,49 @@ -Abacus.Partitions (VERSION = 0.5.0) +Abacus.Partitions (VERSION = 0.5.1) --- +o = Abacus.Partition(7) +o.total() +15 +o.next() +[ 1, 1, 1, 1, 1, 1, 1 ] +o.hasNext() +true +o.next() +[ 2, 1, 1, 1, 1, 1 ] +default order is "lex", lexicographic-order +o.rewind() +[ 1, 1, 1, 1, 1, 1, 1 ] +[ 2, 1, 1, 1, 1, 1 ] +[ 2, 2, 1, 1, 1 ] +[ 2, 2, 2, 1 ] +[ 3, 1, 1, 1, 1 ] +[ 3, 2, 1, 1 ] +[ 3, 2, 2 ] +[ 3, 3, 1 ] +[ 4, 1, 1, 1 ] +[ 4, 2, 1 ] +[ 4, 3 ] +[ 5, 1, 1 ] +[ 5, 2 ] +[ 6, 1 ] +[ 7 ] +backwards +o.rewind(-1) +[ 7 ] +[ 6, 1 ] +[ 5, 2 ] +[ 5, 1, 1 ] +[ 4, 3 ] +[ 4, 2, 1 ] +[ 4, 1, 1, 1 ] +[ 3, 3, 1 ] +[ 3, 2, 2 ] +[ 3, 2, 1, 1 ] +[ 3, 1, 1, 1, 1 ] +[ 2, 2, 2, 1 ] +[ 2, 2, 1, 1, 1 ] +[ 2, 1, 1, 1, 1, 1 ] +[ 1, 1, 1, 1, 1, 1, 1 ] +o.dispose() o = Abacus.Partition(8) o.total() 22 @@ -34,7 +78,7 @@ o.rewind() [ 7, 1 ] [ 8 ] backwards -o.forward() +o.rewind(-1) [ 8 ] [ 7, 1 ] [ 6, 2 ] @@ -58,3 +102,67 @@ o.forward() [ 2, 1, 1, 1, 1, 1, 1 ] [ 1, 1, 1, 1, 1, 1, 1, 1 ] o.dispose() +o = Abacus.Partition(7,{max:4}) +o.total() +3 +default order is "lex", lexicographic-order +o.rewind() +[ 4, 1, 1, 1 ] +[ 4, 2, 1 ] +[ 4, 3 ] +backwards +o.rewind(-1) +[ 4, 3 ] +[ 4, 2, 1 ] +[ 4, 1, 1, 1 ] +o.dispose() +o = Abacus.Partition(8,{max:4}) +o.total() +5 +default order is "lex", lexicographic-order +o.rewind() +[ 4, 1, 1, 1, 1 ] +[ 4, 2, 1, 1 ] +[ 4, 2, 2 ] +[ 4, 3, 1 ] +[ 4, 4 ] +backwards +o.rewind(-1) +[ 4, 4 ] +[ 4, 3, 1 ] +[ 4, 2, 2 ] +[ 4, 2, 1, 1 ] +[ 4, 1, 1, 1, 1 ] +o.dispose() +o = Abacus.Partition(8,{exactly:4}) +o.total() +5 +default order is "lex", lexicographic-order +o.rewind() +[ 2, 2, 2, 2 ] +[ 3, 2, 2, 1 ] +[ 3, 3, 1, 1 ] +[ 4, 2, 1, 1 ] +[ 5, 1, 1, 1 ] +backwards +o.rewind(-1) +[ 5, 1, 1, 1 ] +[ 4, 2, 1, 1 ] +[ 3, 3, 1, 1 ] +[ 3, 2, 2, 1 ] +[ 2, 2, 2, 2 ] +o.dispose() +o = Abacus.Partition(7,{exactly:4}) +o.total() +3 +default order is "lex", lexicographic-order +o.rewind() +[ 2, 2, 2, 1 ] +[ 3, 2, 1, 1 ] +[ 4, 1, 1, 1 ] +backwards +o.rewind(-1) +[ 4, 1, 1, 1 ] +[ 3, 2, 1, 1 ] +[ 2, 2, 2, 1 ] +o.dispose() diff --git a/test/permutations-bigint.txt b/test/permutations-bigint.txt index 890e4fe..ddf8c43 100644 --- a/test/permutations-bigint.txt +++ b/test/permutations-bigint.txt @@ -1,59 +1,59 @@ -Abacus.Permutations (VERSION = 0.5.0) +Abacus.Permutations (VERSION = 0.5.1) --- o = Abacus.Permutation(50) o.total() 30414093201713378043612608166064768844377641568960512000000000000 o.random() -[ 6, - 36, +[ 27, + 17, + 8, + 19, + 20, 3, - 13, - 2, - 49, 42, - 43, - 32, + 24, + 10, + 41, + 31, + 28, 0, - 35, - 45, - 11, - 7, - 27, - 12, + 1, + 34, + 49, + 16, 48, - 39, - 33, - 41, 25, + 39, + 13, + 18, + 43, + 4, 5, - 37, - 47, - 38, - 15, - 29, + 32, + 36, + 6, + 40, 23, + 12, + 33, 46, 9, - 40, - 1, - 17, - 18, - 31, - 44, - 19, 22, - 14, - 8, - 24, - 34, - 10, + 37, + 44, + 15, + 11, 30, - 21, - 4, + 29, 26, - 28, - 20, - 16 ] + 45, + 47, + 38, + 2, + 35, + 14, + 21, + 7 ] o.item(78043612608166064768844377641568960512000000000000,"lex") [ 0, 1, diff --git a/test/permutations.js b/test/permutations.js index a0a3db7..f0500e9 100644 --- a/test/permutations.js +++ b/test/permutations.js @@ -1,11 +1,10 @@ var isNode = 'undefined' !== typeof global && '[object global]' === {}.toString.call(global); var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = console.log; - function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -38,20 +37,24 @@ echo(o.next()); echo('default order is "lex", lexicographic-order'); echo('o.rewind()'); print_all( o.rewind(), 1, function( item ){ + var index = o.index()-(o.hasNext()?1:0), + rank = Abacus.Permutation.rank(item); return [ item.slice(), - "index : " + (o.index()-(o.hasNext()?1:0)), // object index points at next item when this is printed - "rank : " + Abacus.Permutation.rank(item), + "index : " + index, + "rank : " + rank, + "unrank : " + Abacus.Permutation.unrank(rank, o.n).join(','), "is_permutation : " + (Abacus.Permutation.is_permutation(item)?"yes":"no"), "is_identity : " + (Abacus.Permutation.is_identity(item)?"yes":"no"), "is_derangement : " + (Abacus.Permutation.is_derangement(item)?"yes":"no"), - "is_involution : " + (Abacus.Permutation.is_involution(item)?"yes":"no") + "is_involution : " + (Abacus.Permutation.is_involution(item)?"yes":"no"), + "is_connected : " + (Abacus.Permutation.is_connected(item)?"yes":"no") ]; }); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/permutations.txt b/test/permutations.txt index adc9a1c..a7aad4a 100644 --- a/test/permutations.txt +++ b/test/permutations.txt @@ -1,4 +1,4 @@ -Abacus.Permutations (VERSION = 0.5.0) +Abacus.Permutations (VERSION = 0.5.1) --- o = Abacus.Permutation(4) o.total() @@ -14,173 +14,221 @@ o.rewind() [ [ 0, 1, 2, 3 ], 'index : 0', 'rank : 0', + 'unrank : 0,1,2,3', 'is_permutation : yes', 'is_identity : yes', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 1, 3, 2 ], 'index : 1', 'rank : 1', + 'unrank : 0,1,3,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 2, 1, 3 ], 'index : 2', 'rank : 2', + 'unrank : 0,2,1,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 0, 2, 3, 1 ], 'index : 3', 'rank : 3', + 'unrank : 0,2,3,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 0, 3, 1, 2 ], 'index : 4', 'rank : 4', + 'unrank : 0,3,1,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 0, 3, 2, 1 ], 'index : 5', 'rank : 5', + 'unrank : 0,3,2,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 0, 2, 3 ], 'index : 6', 'rank : 6', + 'unrank : 1,0,2,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 0, 3, 2 ], 'index : 7', 'rank : 7', + 'unrank : 1,0,3,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 1, 2, 0, 3 ], 'index : 8', 'rank : 8', + 'unrank : 1,2,0,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 1, 2, 3, 0 ], 'index : 9', 'rank : 9', + 'unrank : 1,2,3,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 1, 3, 0, 2 ], 'index : 10', 'rank : 10', + 'unrank : 1,3,0,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 1, 3, 2, 0 ], 'index : 11', 'rank : 11', + 'unrank : 1,3,2,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 0, 1, 3 ], 'index : 12', 'rank : 12', + 'unrank : 2,0,1,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 2, 0, 3, 1 ], 'index : 13', 'rank : 13', + 'unrank : 2,0,3,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 1, 0, 3 ], 'index : 14', 'rank : 14', + 'unrank : 2,1,0,3', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 2, 1, 3, 0 ], 'index : 15', 'rank : 15', + 'unrank : 2,1,3,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 2, 3, 0, 1 ], 'index : 16', 'rank : 16', + 'unrank : 2,3,0,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 2, 3, 1, 0 ], 'index : 17', 'rank : 17', + 'unrank : 2,3,1,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 3, 0, 1, 2 ], 'index : 18', 'rank : 18', + 'unrank : 3,0,1,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 0, 2, 1 ], 'index : 19', 'rank : 19', + 'unrank : 3,0,2,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 1, 0, 2 ], 'index : 20', 'rank : 20', + 'unrank : 3,1,0,2', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : yes' ] [ [ 3, 1, 2, 0 ], 'index : 21', 'rank : 21', + 'unrank : 3,1,2,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : no', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] [ [ 3, 2, 0, 1 ], 'index : 22', 'rank : 22', + 'unrank : 3,2,0,1', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : no' ] + 'is_involution : no', + 'is_connected : no' ] [ [ 3, 2, 1, 0 ], 'index : 23', 'rank : 23', + 'unrank : 3,2,1,0', 'is_permutation : yes', 'is_identity : no', 'is_derangement : yes', - 'is_involution : yes' ] + 'is_involution : yes', + 'is_connected : no' ] backwards -o.forward() +o.rewind(-1) [ 3, 2, 1, 0 ] [ 3, 2, 0, 1 ] [ 3, 1, 2, 0 ] @@ -331,32 +379,32 @@ o.order("colex,reversed") [ 2, 3, 1, 0 ] [ 3, 2, 1, 0 ] o.order("random") -[ 1, 2, 0, 3 ] -[ 3, 1, 2, 0 ] -[ 0, 3, 2, 1 ] [ 1, 3, 0, 2 ] -[ 1, 3, 2, 0 ] -[ 2, 1, 3, 0 ] -[ 1, 0, 3, 2 ] -[ 2, 3, 1, 0 ] -[ 3, 0, 2, 1 ] -[ 2, 1, 0, 3 ] -[ 3, 2, 0, 1 ] -[ 3, 0, 1, 2 ] -[ 0, 3, 1, 2 ] [ 0, 2, 3, 1 ] -[ 1, 0, 2, 3 ] -[ 1, 2, 3, 0 ] -[ 2, 3, 0, 1 ] +[ 2, 3, 1, 0 ] [ 0, 2, 1, 3 ] [ 0, 1, 3, 2 ] +[ 1, 2, 0, 3 ] +[ 0, 3, 2, 1 ] +[ 2, 3, 0, 1 ] [ 0, 1, 2, 3 ] +[ 1, 0, 2, 3 ] +[ 3, 2, 1, 0 ] +[ 1, 0, 3, 2 ] +[ 3, 1, 0, 2 ] [ 2, 0, 1, 3 ] +[ 1, 2, 3, 0 ] +[ 1, 3, 2, 0 ] +[ 3, 0, 2, 1 ] [ 2, 0, 3, 1 ] -[ 3, 1, 0, 2 ] -[ 3, 2, 1, 0 ] -o.random() +[ 3, 1, 2, 0 ] +[ 2, 1, 3, 0 ] [ 0, 3, 1, 2 ] +[ 3, 2, 0, 1 ] +[ 3, 0, 1, 2 ] +[ 2, 1, 0, 3 ] +o.random() +[ 0, 1, 3, 2 ] o.order("colex").range(-5, -1) [ 1, 2, 0, 3 ] [ 2, 0, 1, 3 ] diff --git a/test/subsets.js b/test/subsets.js index 9a40014..0422d44 100644 --- a/test/subsets.js +++ b/test/subsets.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -39,8 +39,8 @@ echo('o.rewind()'); print_all( o.rewind() ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/subsets.txt b/test/subsets.txt index 04a8922..03287cf 100644 --- a/test/subsets.txt +++ b/test/subsets.txt @@ -1,4 +1,4 @@ -Abacus.Subsets (VERSION = 0.5.0) +Abacus.Subsets (VERSION = 0.5.1) --- o = Abacus.Subset(5) o.total() @@ -44,7 +44,7 @@ o.rewind() [ 4, 3, 2, 1 ] [ 4, 3, 2, 1, 0 ] backwards -o.forward() +o.rewind(-1) [ 4, 3, 2, 1, 0 ] [ 4, 3, 2, 1 ] [ 4, 3, 2, 0 ] @@ -149,31 +149,31 @@ o.order("colex") [ 1 ] [ 0, 1 ] [ 2 ] -[ 0, 2 ] +[ 0, 1 ] [ 1, 2 ] [ 0, 1, 2 ] [ 3 ] -[ 0, 3 ] -[ 1, 3 ] -[ 0, 1, 3 ] +[ 0, 1 ] +[ 1, 2 ] +[ 0, 1, 2 ] [ 2, 3 ] -[ 0, 2, 3 ] +[ 0, 1, 2 ] [ 1, 2, 3 ] [ 0, 1, 2, 3 ] [ 4 ] -[ 0, 4 ] -[ 1, 4 ] -[ 0, 1, 4 ] -[ 2, 4 ] -[ 0, 2, 4 ] -[ 1, 2, 4 ] -[ 0, 1, 2, 4 ] +[ 0, 1 ] +[ 1, 2 ] +[ 0, 1, 2 ] +[ 2, 3 ] +[ 0, 1, 2 ] +[ 1, 2, 3 ] +[ 0, 1, 2, 3 ] [ 3, 4 ] -[ 0, 3, 4 ] -[ 1, 3, 4 ] -[ 0, 1, 3, 4 ] +[ 0, 1, 2 ] +[ 1, 2, 3 ] +[ 0, 1, 2, 3 ] [ 2, 3, 4 ] -[ 0, 2, 3, 4 ] +[ 0, 1, 2, 3 ] [ 1, 2, 3, 4 ] [ 0, 1, 2, 3, 4 ] o.order("colex,reflected") @@ -182,105 +182,105 @@ o.order("colex,reflected") [ 1 ] [ 1, 0 ] [ 2 ] -[ 2, 0 ] +[ 1, 0 ] [ 2, 1 ] [ 2, 1, 0 ] [ 3 ] -[ 3, 0 ] -[ 3, 1 ] -[ 3, 1, 0 ] +[ 1, 0 ] +[ 2, 1 ] +[ 2, 1, 0 ] [ 3, 2 ] -[ 3, 2, 0 ] +[ 2, 1, 0 ] [ 3, 2, 1 ] [ 3, 2, 1, 0 ] [ 4 ] -[ 4, 0 ] -[ 4, 1 ] -[ 4, 1, 0 ] -[ 4, 2 ] -[ 4, 2, 0 ] -[ 4, 2, 1 ] -[ 4, 2, 1, 0 ] +[ 1, 0 ] +[ 2, 1 ] +[ 2, 1, 0 ] +[ 3, 2 ] +[ 2, 1, 0 ] +[ 3, 2, 1 ] +[ 3, 2, 1, 0 ] [ 4, 3 ] -[ 4, 3, 0 ] -[ 4, 3, 1 ] -[ 4, 3, 1, 0 ] +[ 2, 1, 0 ] +[ 3, 2, 1 ] +[ 3, 2, 1, 0 ] [ 4, 3, 2 ] -[ 4, 3, 2, 0 ] +[ 3, 2, 1, 0 ] [ 4, 3, 2, 1 ] [ 4, 3, 2, 1, 0 ] o.order("colex,reversed") [ 0, 1, 2, 3, 4 ] [ 1, 2, 3, 4 ] -[ 0, 2, 3, 4 ] +[ 0, 1, 2, 3 ] [ 2, 3, 4 ] -[ 0, 1, 3, 4 ] -[ 1, 3, 4 ] -[ 0, 3, 4 ] +[ 0, 1, 2, 3 ] +[ 1, 2, 3 ] +[ 0, 1, 2 ] [ 3, 4 ] -[ 0, 1, 2, 4 ] -[ 1, 2, 4 ] -[ 0, 2, 4 ] -[ 2, 4 ] -[ 0, 1, 4 ] -[ 1, 4 ] -[ 0, 4 ] +[ 0, 1, 2, 3 ] +[ 1, 2, 3 ] +[ 0, 1, 2 ] +[ 2, 3 ] +[ 0, 1, 2 ] +[ 1, 2 ] +[ 0, 1 ] [ 4 ] [ 0, 1, 2, 3 ] [ 1, 2, 3 ] -[ 0, 2, 3 ] +[ 0, 1, 2 ] [ 2, 3 ] -[ 0, 1, 3 ] -[ 1, 3 ] -[ 0, 3 ] +[ 0, 1, 2 ] +[ 1, 2 ] +[ 0, 1 ] [ 3 ] [ 0, 1, 2 ] [ 1, 2 ] -[ 0, 2 ] +[ 0, 1 ] [ 2 ] [ 0, 1 ] [ 1 ] [ 0 ] [] o.order("random") -[ 4, 3, 1, 0 ] -[ 4, 3, 2, 1 ] -[ 4 ] +[] +[ 4, 1, 0 ] +[ 4, 3, 2 ] +[ 0 ] [ 4, 3, 2, 0 ] +[ 2, 0 ] +[ 4, 3, 2, 1, 0 ] +[ 4, 1 ] +[ 4, 2, 1, 0 ] +[ 1 ] +[ 4, 3, 2, 1 ] +[ 4, 3, 1, 0 ] +[ 3, 1, 0 ] [ 3, 2, 1 ] -[ 4, 3, 2 ] -[ 3 ] -[ 4, 3, 0 ] [ 4, 3, 1 ] +[ 3, 1 ] +[ 3, 2, 0 ] +[ 4, 2, 1 ] [ 2 ] -[ 2, 1 ] -[ 4, 2, 0 ] -[ 4, 1 ] -[ 4, 3 ] +[ 4, 3, 0 ] [ 1, 0 ] -[ 4, 1, 0 ] +[ 4, 3 ] +[ 4, 2, 0 ] +[ 2, 1 ] [ 4, 2 ] -[ 4, 2, 1, 0 ] -[ 3, 2, 1, 0 ] [ 2, 1, 0 ] +[ 3 ] +[ 4, 0 ] [ 3, 0 ] -[ 4, 2, 1 ] -[ 3, 2, 0 ] -[ 3, 1 ] -[ 4, 3, 2, 1, 0 ] +[ 4 ] +[ 3, 2, 1, 0 ] [ 3, 2 ] -[ 2, 0 ] -[ 3, 1, 0 ] -[ 4, 0 ] -[] -[ 1 ] -[ 0 ] o.random() -[ 4, 3 ] +[ 2, 1 ] o.order("colex").range(-5, -1) -[ 0, 1, 3, 4 ] +[ 0, 1, 2, 3 ] [ 2, 3, 4 ] -[ 0, 2, 3, 4 ] +[ 0, 1, 2, 3 ] [ 1, 2, 3, 4 ] [ 0, 1, 2, 3, 4 ] o.dispose() diff --git a/test/tensors.js b/test/tensors.js index 69ca46a..7b30b62 100644 --- a/test/tensors.js +++ b/test/tensors.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -39,8 +39,8 @@ echo('o.rewind()'); print_all( o.rewind() ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/tensors.txt b/test/tensors.txt index 6e66da7..c4432f3 100644 --- a/test/tensors.txt +++ b/test/tensors.txt @@ -1,4 +1,4 @@ -Abacus.Tensors (VERSION = 0.5.0) +Abacus.Tensors (VERSION = 0.5.1) --- o = Abacus.Tensor(1,2,3) o.total() @@ -18,7 +18,7 @@ o.rewind() [ 0, 1, 1 ] [ 0, 1, 2 ] backwards -o.forward() +o.rewind(-1) [ 0, 1, 2 ] [ 0, 1, 1 ] [ 0, 1, 0 ] @@ -61,14 +61,14 @@ o.order("colex,reversed") [ 1, 0, 0 ] [ 0, 0, 0 ] o.order("random") -[ 0, 0, 0 ] -[ 0, 1, 0 ] -[ 0, 0, 2 ] -[ 0, 1, 2 ] [ 0, 0, 1 ] [ 0, 1, 1 ] +[ 0, 1, 2 ] +[ 0, 1, 0 ] +[ 0, 0, 0 ] +[ 0, 0, 2 ] o.random() -[ 0, 1, 1 ] +[ 0, 0, 1 ] o.order("colex").range(-5, -1) [ 1, 0, 0 ] [ 2, 0, 0 ] diff --git a/test/tuples.js b/test/tuples.js index 1d4dff2..3ca7b22 100644 --- a/test/tuples.js +++ b/test/tuples.js @@ -4,7 +4,7 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con function print_all( o, prev, f ) { if ( -1 === prev ) - while ( o.hasPrev() ) echo( f ? f(o.prev()) : o.prev() ); + while ( o.hasNext(-1) ) echo( f ? f(o.next(-1)) : o.next(-1) ); else //while ( o.hasNext() ) echo( o.next() ); // iterator/iterable are supported @@ -39,8 +39,8 @@ echo('o.rewind()'); print_all( o.rewind() ); echo('backwards'); -echo('o.forward()'); -print_all( o.forward(), -1 ); +echo('o.rewind(-1)'); +print_all( o.rewind(-1), -1 ); echo('o.order("lex,reflected")'); print_all( o.order("lex,reflected") ); diff --git a/test/tuples.txt b/test/tuples.txt index 2b55768..7cb194d 100644 --- a/test/tuples.txt +++ b/test/tuples.txt @@ -1,4 +1,4 @@ -Abacus.Tuples (VERSION = 0.5.0) +Abacus.Tuples (VERSION = 0.5.1) --- o = Abacus.Tuple(3,3) o.total() @@ -39,7 +39,7 @@ o.rewind() [ 2, 2, 1 ] [ 2, 2, 2 ] backwards -o.forward() +o.rewind(-1) [ 2, 2, 2 ] [ 2, 2, 1 ] [ 2, 2, 0 ] @@ -208,35 +208,35 @@ o.order("colex,reversed") [ 1, 0, 0 ] [ 0, 0, 0 ] o.order("random") -[ 1, 0, 1 ] -[ 1, 1, 2 ] -[ 0, 2, 1 ] -[ 1, 0, 2 ] -[ 1, 0, 0 ] -[ 2, 2, 1 ] -[ 2, 1, 2 ] -[ 0, 2, 2 ] -[ 2, 0, 0 ] [ 1, 2, 2 ] -[ 1, 1, 0 ] -[ 1, 2, 1 ] -[ 1, 1, 1 ] -[ 0, 2, 0 ] -[ 2, 1, 1 ] +[ 2, 0, 0 ] [ 1, 2, 0 ] +[ 0, 2, 2 ] +[ 1, 1, 2 ] [ 2, 0, 1 ] -[ 2, 2, 2 ] -[ 2, 2, 0 ] -[ 2, 1, 0 ] -[ 2, 0, 2 ] -[ 0, 0, 0 ] +[ 0, 2, 1 ] +[ 1, 1, 0 ] [ 0, 1, 2 ] -[ 0, 1, 1 ] [ 0, 1, 0 ] +[ 2, 1, 2 ] +[ 1, 0, 0 ] +[ 1, 0, 1 ] [ 0, 0, 2 ] +[ 1, 0, 2 ] +[ 0, 0, 0 ] +[ 0, 1, 1 ] +[ 2, 0, 2 ] +[ 1, 2, 1 ] +[ 0, 2, 0 ] [ 0, 0, 1 ] +[ 1, 1, 1 ] +[ 2, 1, 0 ] +[ 2, 1, 1 ] +[ 2, 2, 0 ] +[ 2, 2, 2 ] +[ 2, 2, 1 ] o.random() -[ 0, 2, 0 ] +[ 2, 0, 2 ] o.order("colex").range(-5, -1) [ 1, 1, 2 ] [ 2, 1, 2 ]