RosettaCodeData/Task/Zig-zag-matrix/Factor/zig-zag-matrix-2.factor

12 lines
368 B
Factor
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
USING: assocs assocs.extras grouping io kernel math
math.combinatorics math.matrices prettyprint sequences ;
: <zig-zag-matrix> ( n -- matrix )
[
dup [ + ] <matrix-by-indices> concat zip-index
expand-keys-push-at values [ even? [ reverse ] when ]
map-index concat inverse-permutation
] [ group ] bi ;
5 <zig-zag-matrix> simple-table.