Coder Profile - Show off your skills, get a coder profile.
 
 
 
The Author
Cinjection
Oleksi Derkatch
Send A Message
Rating
9.00
out of 10
( 2 Ratings )
Please login to rate source codes.

Click here to register a free account with us.
General Details
Scheme
Posted 104 Days Ago
197 Views
Received 2 Ratings
More Codes By This Author
MD5 Brute-Forcer
Number of ways to make ch...
SPS Desktop Changer
Simple program using GUI...
Genetic Algorithm for sol...
Articles By This Author
Intorduction to memoizati...
Strings in C++
Vectors in C++
Use Cases
[C++] Pointers and their...

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.
 
closure     Posted 104 Days Ago
 
 
Hi,
good one. You might want to have a look at srfi-1 FOLD.

cheers
Page 1 of 1
More "Scheme" Source Codes By This Author
Recently Posted "Scheme" Source Codes
Recently Rated "Scheme" Source Codes
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved