Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
USING: hash-sets kernel locals math sequences sets ;
IN: acm
:: add ( set n -- newset )
HS{ } clone :> newset
set members [ n [ + ] [ - ] 2bi [ newset adjoin ] bi@ ] each newset ;
:: least ( n -- x )
HS{ 0 } 1 [ [ add n over in? ] keep swap ] [ 1 + ] until nip ;
( scratchpad ) 12 least .
7
( scratchpad ) 21 least .
6
( scratchpad ) 100000 least .
447
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment