Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Scheme/DrRacket

Name: Anonymous 2012-12-02 12:58

How do you do this shit /prog/?

Write a Scheme function evens-odds (using at least one abstract list function), which consumes a list of numbers lst and produces the difference between the sum of the odd numbers and the sum of the even numbers in the list lst. Some examples follow:


(evens-odds (list 1 2 3 4)) => -2
(evens-odds empty) => 0
(evens-odds (list 2 4 16)) => -22
(evens-odds (list 1 3 7 21 13)) => 45



Note: You should use local function(s) only (in case of need).

Name: Anonymous 2012-12-02 16:31

evensOdds xs = (sum . filter odd $ xs) - (sum . filter even $ xs)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List