aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 9d133a4d69acff5814653a59de0878e76ddd11a4 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# AccelAsc for R7RS

This library provides an implementation of the algorithm called `accel_asc` by Jerome Kelleher, which generates integer partitions in R7RS.
For more details, please refer to [Jerome Keller's website](https://jeromekelleher.net/category/combinatorics.html).

## Requirements

- `(scheme generator)` of R7RS-large or `(srfi 158)`

## Usage

### Library `(integer-partition accel-asc)`

#### `(accel-asc n) → <generator>`

Returns a generator that produces a vector of integers representing integer partitions for the given value of integer `n`.

## Examples

```scheme
(import (scheme base)
        (srfi 158)
        (integer-partition accel-asc))

(generator-for-each (lambda (v) (display v) (newline))
                    (accel-asc 8))
```

Output:

```
#(1 1 1 1 1 1 1 1)
#(1 1 1 1 1 1 2)
#(1 1 1 1 1 3)
#(1 1 1 1 2 2)
#(1 1 1 1 4)
#(1 1 1 2 3)
#(1 1 1 5)
#(1 1 2 2 2)
#(1 1 2 4)
#(1 1 3 3)
#(1 1 6)
#(1 2 2 3)
#(1 2 5)
#(1 3 4)
#(1 7)
#(2 2 2 2)
#(2 2 4)
#(2 3 3)
#(2 6)
#(3 5)
#(4 4)
#(8)
```

## License

This library is released under the Apache License Version 2.0.
See the LICENSE file for more details.

## References

- Kelleher, J. (2006). *Encoding partitions as ascending compositions* [Doctoral dissertation, University College Cork]. [https://jeromekelleher.net/downloads/k06.pdf](https://jeromekelleher.net/downloads/k06.pdf)
- Kelleher, J. (2014, May 26). *Generating Integer Partitions*. [https://jeromekelleher.net/generating-integer-partitions.html](https://jeromekelleher.net/generating-integer-partitions.html)

## Copyright

Copyright (c) 2024 Masaya Tojo <masaya@tojo.tokyo>