sorry i forgot to attach.... here it is

On Sat, Dec 25, 2010 at 10:34 PM, Puneet Ginoria <punnu.gino...@gmail.com>wrote:

> This attachment contains the code for the above program in SML language and
> it uses lambda calculus.
>
>
> On Sat, Dec 25, 2010 at 9:18 PM, juver++ <avpostni...@gmail.com> wrote:
>
>> What you need to get for the answer - amount of such subsets or display
>> them?
>> First problem can be solved using DP.
>> Second - brute force.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

fun depthfirst next pred x =
        let
                fun dfs([]) = []
                  | dfs(x::xs)  =
                        if pred(x) then x::dfs(xs)
                        else dfs(next(x) @ xs)
        in
                dfs([x])
        end;


fun sum([]) = 0 | sum(x::xs) = x + sum(xs);

fun check n ls = (sum(ls)=n);

fun last([]) = []
        |last(x::xs) = if xs=[] then [x] else last(xs);

fun filt([],soln) = []
        |filt(x::xs,soln) = 
                let
                        fun helper(x::xs,[y]) = if x=y then xs else 
helper(xs,[y])
                in
                        if last(soln) = [] then (x::xs) else 
helper(x::xs,last(soln))
                end;


fun listify(soln,[]) = []
        |listify(soln,x::xs) = (op@(soln,[x]))::listify(soln,xs);

fun nextset ls soln = listify(soln,filt(ls,soln));

fun subset ls n = depthfirst (nextset ls) (check n) [];

Reply via email to