 : perfect-square? ( n -- ? )
     dup sqrt mod zero? ;
 
-<PRIVATE
-
-: count-digits ( n -- byte-array )
-    10 <byte-array> [
-        '[ 10 /mod _ [ 1 + ] change-nth dup 0 > ] loop drop
-    ] keep ;
-
-HINTS: count-digits fixnum ;
-
-: max-children ( seq -- seq )
-    [ dup length 1 - <iota> [ nth-pair max , ] with each ] { } make ;
-
-! Propagate one row into the upper one
-: propagate ( bottom top -- newtop )
-    [ over rest rot first2 max rot + ] map nip ;
-
-: (sum-divisors) ( n -- sum )
-    dup sqrt >integer [1,b] [
-        [ 2dup divisor? [ 2dup / + , ] [ drop ] if ] each
-        dup perfect-square? [ sqrt >fixnum neg , ] [ drop ] if
-    ] { } make sum ;
-
-: transform ( triple matrix -- new-triple )
-    [ 1array ] dip m. first ;
-
-PRIVATE>
-
 : alpha-value ( str -- n )
     >lower [ CHAR: a - 1 + ] map-sum ;
 
 : mediant ( a/c b/d -- (a+b)/(c+d) )
     2>fraction [ + ] 2bi@ / ;
+
+<PRIVATE
+
+: max-children ( seq -- seq )
+    [ dup length 1 - <iota> [ nth-pair max , ] with each ] { } make ;
+
+PRIVATE>
 
 : max-path ( triangle -- n )
     dup length 1 > [

    [ propagate dup ] map nip
    reverse swap suffix ;

: permutations? ( n m -- ? )
    [ count-digits ] same? ;

: sum-divisors ( n -- sum )
    dup 4 < [ { 0 1 3 4 } nth ] [ (sum-divisors) ] if ;

        dupd divisor? [ [ 2 + ] dip ] when
    ] each drop * ;

<PRIVATE

: transform ( triple matrix -- new-triple )
    [ 1array ] dip m. first ;

PRIVATE>

! These transforms are for generating primitive Pythagorean triples
: u-transform ( triple -- new-triple )
    { { 1 2 2 } { -2 -1 -2 } { 2 2 3 } } transform ;
