Skip to content

Instantly share code, notes, and snippets.

@siraben
Last active January 7, 2019 13:53
Show Gist options
  • Save siraben/4b1648c311df16829874b6c08ecba150 to your computer and use it in GitHub Desktop.
Save siraben/4b1648c311df16829874b6c08ecba150 to your computer and use it in GitHub Desktop.
Small backtracking
: ENTER >R ;
: SUCC ' R@ , ' ENTER , ; IMMEDIATE
: FAIL ' R> , ' DROP , ' EXIT , ; IMMEDIATE
: RANGE
1+ >R 1-
CREATE
' LIT ,
,
POSTPONE BEGIN
' 1+ ,
' DUP ,
' LIT ,
R> ,
' < ,
POSTPONE WHILE
POSTPONE SUCC
POSTPONE REPEAT
' DROP ,
POSTPONE FAIL
' EXIT ,
;
1 10 RANGE 1-10
: //2 DUP 2 MOD 0= IF SUCC THEN FAIL ;
: .even1-10 1-10 //2 DUP . ;
.even1-10 \ 2 4 6 8 10
: el R@ ENTER DROP ;
: .{} CR ." { " DEPTH 0 2DUP = IF 2DROP ELSE DO I PICK . LOOP THEN ." } " ;
: subsets 1
el 2
el 3
el .{} ;
PAGE subsets
SHUTDOWN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment