aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md20
-rw-r--r--README.md16
-rw-r--r--integer-partition/accel-asc.scm61
3 files changed, 33 insertions, 64 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55c57f6..068ae31 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,25 +3,13 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [Unreleased]
-
-## [1.1.0]
-
-### Added
-
-- Add Changelog section in README.md file.
-- Add Source code section in README.md file.
-- Add comments to describe the algorithm used in accel-asc procedure.
-- Add `(accel-asc n vector->)` procedure.
-
## [1.0.0] - 2024-08-23
### Added
-- `(integer-partition accel-asc)` library.
-- CHANGELOG.md file.
-- README.md file.
-- LICENSE file.
+- `(integer-partition accel-asc)` library
+- CHANGELOG.md file
+- README.md file
+- LICENSE file
[1.0.0]: https://git.tojo.tokyo/r7rs-accel-asc.git/diff/?id=v1.0.0
-[1.1.0]: https://git.tojo.tokyo/r7rs-accel-asc.git/diff/?id=v1.0.0&id2=v1.1.0
diff --git a/README.md b/README.md
index ac90b41..aa4fd98 100644
--- a/README.md
+++ b/README.md
@@ -54,22 +54,6 @@ Output:
#(8)
```
-## Source code
-
-### Use git command
-
-To clone the repository `r7rs-accel-asc`, you can use the following git command:
-
-```shell
-git clone https://git.tojo.tokyo/r7rs-accel-asc.git
-```
-
-After cloning, you can explore the code and integrate it into your R7RS projects.
-
-## Changelog
-
-See the [CHANGELOG.md](./CHANGELOG.md) file.
-
## License
This library is released under the Apache License Version 2.0.
diff --git a/integer-partition/accel-asc.scm b/integer-partition/accel-asc.scm
index e8982c2..870cb0b 100644
--- a/integer-partition/accel-asc.scm
+++ b/integer-partition/accel-asc.scm
@@ -14,8 +14,7 @@
(define-library (integer-partition accel-asc)
(export accel-asc)
- (import (scheme base)
- (scheme case-lambda))
+ (import (scheme base))
(cond-expand
((library (scheme generator))
(import (only (scheme generator) make-coroutine-generator)))
@@ -33,33 +32,31 @@
(loop))
(if #f #f)))))))
(begin
- ;; This is a Scheme implementation of Jerome Kelleher's algorithm for generating integer paritions.
- ;; See: https://jeromekelleher.net/category/combinatorics.html
- (define accel-asc
- (case-lambda
- ((n)
- (accel-asc n vector-copy))
- ((n vector->)
- (make-coroutine-generator
- (lambda (yield)
- (let ((a (make-vector (+ n 1) 0))
- (k 1)
- (x 0)
- (y (- n 1)))
- (while (not (= k 0))
- (set! x (+ (vector-ref a (- k 1)) 1))
- (set! k (- k 1))
- (while (<= (* 2 x) y)
- (vector-set! a k x)
- (set! y (- y x))
- (set! k (+ k 1)))
- (let ((l (+ k 1)))
- (while (<= x y)
- (vector-set! a k x)
- (vector-set! a l y)
- (yield (vector-> a 0 (+ k 2)))
- (set! x (+ x 1))
- (set! y (- y 1)))
- (vector-set! a k (+ x y))
- (set! y (+ x y -1))
- (yield (vector-> a 0 (+ k 1)))))))))))))
+ (define (accel-asc n)
+ (accel-asc* n vector-copy))
+
+ (define (accel-asc* n convert)
+ (make-coroutine-generator
+ (lambda (yield)
+ (let ((a (make-vector (+ n 1) 0))
+ (k 1)
+ (x 0)
+ (y (- n 1)))
+ (while (not (= k 0))
+ (set! x (+ (vector-ref a (- k 1)) 1))
+ (set! k (- k 1))
+ (while (<= (* 2 x) y)
+ (vector-set! a k x)
+ (set! y (- y x))
+ (set! k (+ k 1)))
+ (let ((l (+ k 1)))
+ (while (<= x y)
+ (vector-set! a k x)
+ (vector-set! a l y)
+ (yield (convert a 0 (+ k 2)))
+ (set! x (+ x 1))
+ (set! y (- y 1)))
+ (vector-set! a k (+ x y))
+ (set! y (+ x y -1))
+ (yield (convert a 0 (+ k 1)))))))))
+ ))