Last active
January 7, 2019 13:53
-
-
Save siraben/4b1648c311df16829874b6c08ecba150 to your computer and use it in GitHub Desktop.
Small backtracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: 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