]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/combinatorics/combinatorics.factor
factor: Move math.ranges => ranges.
[factor.git] / extra / benchmark / combinatorics / combinatorics.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: combinators kernel math math.combinatorics ranges
5 sequences ;
6
7 IN: benchmark.combinatorics
8
9 : bench-combinations ( n -- )
10     [1..b] dup clone [
11         {
12             [ all-combinations drop ]
13             [ [ drop ] each-combination ]
14             [ [ first 2 = ] find-combination drop ]
15             [ 0 [ sum + ] reduce-combinations drop ]
16         } 2cleave
17     ] with each ;
18
19 : bench-permutations ( n -- )
20     <iota> {
21         [ all-permutations drop ]
22         [ [ drop ] each-permutation ]
23         [ [ first 2 = ] find-permutation drop ]
24         [ 0 [ sum + ] reduce-permutations drop ]
25     } cleave ;
26
27 : combinatorics-benchmark ( -- )
28     15 bench-combinations 8 bench-permutations ;
29
30 MAIN: combinatorics-benchmark