|
General Details
|
|
Scheme
|
|
Posted 104 Days Ago
|
|
197 Views
|
|
Received 2 Ratings
|
|
Filtered Accumulator
Description
This is the first thing I made in Scheme that really impressed me. This function is really flexible and allows me to accumulate values (add, subtract, multiply, whatever) in between a range. This function also provides a filter for accumulating only certain values (ones that met a condition). Here are some examples of this: (for definitions of this, inc, and always, see code)
(filter-accumulate + 0 0 10 this inc always) ;Sum of the first 10 digits
(filter-accumulate * 1 1 5 this inc always) ;Factorial of 5.
(filter-accumulate + 0 0 10 this inc (lambda (x) (not (= x 5))))
;Sum of the first 10 digits, not excluding 5
With this function, I was able to complete 4 distinct Project Euler questions (see code below). I was shocked at the flexibility of this thing.
For those of you who know how to use Scheme, please let me know how I can improve this code. Thanks :)
Source Code
Comments
| Please login to post comments. |
|
|
Hi,
good one. You might want to have a look at srfi-1 FOLD.
cheers
|
More "Scheme" Source Codes By This Author
Recently Posted "Scheme" Source Codes
Recently Rated "Scheme" Source Codes
|