Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Subsets of a list
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eli Barzilay  
View profile  
 More options Jan 12 2002, 4:53 am
Newsgroups: comp.lang.scheme
From: Eli Barzilay <e...@barzilay.org>
Date: 12 Jan 2002 04:53:41 -0500
Local: Sat, Jan 12 2002 4:53 am
Subject: Re: Subsets of a list

o...@pobox.com (o...@pobox.com) writes:
> [...]
> In Scheme terms,
> (define (subsets-v23 l n)
>   [...])

When I tried it on my machine, it still runs slower (~9.6 secs) than
the memoization of the simple solution (~7.9 secs) [the numbers are
different than in my other post since I'm on a different machine].

I don't want to jump to conclusions, it's too late so chances are high
that I'm missing something, plus I don't have all those
implementations installed to try...  So can you check how your
configuration runs the simple memoized version?

I assume that gambit and bigloo provide `eq?' hash tables...  The
interface shouldn't be difficult to mimic if it's different -- there's
make-hash-table, (hash-table-put! table key val) and
(hash-table-get table key failure-thunk).  A nice point is that an
efficient `eq?' table is enough since the simple code only calls
itself on cdr's of l.

;;--------------------------------------------------------------------
(define (memoize2 f)
  (let ((table (make-hash-table)))
    (lambda (x y)
      (let ((table2 (hash-table-get table x
                                    (lambda ()
                                      (let ((t (make-hash-table)))
                                        (hash-table-put! table x t)
                                        t)))))
        (hash-table-get table2 y
                        (lambda ()
                          (let ((r (f x y)))
                            (hash-table-put! table2 y r)
                            r)))))))
(define (msubset l n)
  (cond ((<= n 0) '(()))
        ((null? l) '())
        ((= n 1) (map list l))
        (else (append (let ((hd (car l)))
                        (map (lambda (lst) (cons hd lst))
                             (msubset (cdr l) (- n 1))))
                      (msubset (cdr l) n)))))
(set! msubset (memoize2 msubset))
;;--------------------------------------------------------------------

--
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.