Dan, if you put [ /mod swap ] map nip in its own word and gave it a descriptive name then the code would read very well.
Slava On Sun, Apr 5, 2009 at 5:39 PM, Daniel Ehrenberg <[email protected]> wrote: > Kyle, > > Well, here's my attempt at solving the same problem. I use a different > algorithm from you; I think mine should be more efficient. I don't > think there's much shuffling in this version, though maybe the use of > /mod inside map isn't perfectly intention-revealing. > > : change ( amount -- coins ) > { 25 10 5 1 } > [ [ /mod swap ] map nip ] keep > [ <repetition> ] 2map concat ; > > Dan > > On Sun, Apr 5, 2009 at 4:21 PM, Kyle Cordes <[email protected]> wrote: >> I'm trying to get my head around writing (good?) Factor code. Could >> someone point me in the right direction on the snippet below? Even after >> a few rounds of cleanup, I haven't been able to make it very >> intention-revealing, mostly (maybe?) because of juggling three values on >> the stack. >> >> >> USING: kernel sequences math ; >> IN: coins >> >> <PRIVATE >> >> : make-change-with-coin ( coins cents coin -- coins cents ) >> [ 2dup >= ] >> [ tuck - swap tuck [ prefix ] 2dip ] while >> drop ; >> >> PRIVATE> >> >> : change ( cents -- coins ) >> { } swap >> { 25 10 5 1 } [ make-change-with-coin ] each >> drop ; >> >> >> >> ( scratchpad ) 99 change . >> { 1 1 1 1 10 10 25 25 25 } >> >> -- >> Kyle Cordes >> http://kylecordes.com >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Factor-talk mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> > > ------------------------------------------------------------------------------ > _______________________________________________ > Factor-talk mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/factor-talk > ------------------------------------------------------------------------------ _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
