Skip to content

Instantly share code, notes, and snippets.

@olligobber
Created November 25, 2019 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olligobber/0445a1721eb22b1d5b65bb4d4becdbf6 to your computer and use it in GitHub Desktop.
Save olligobber/0445a1721eb22b1d5b65bb4d4becdbf6 to your computer and use it in GitHub Desktop.
Outputs all 1 byte primes using only 7 bytes of memory.
SET POS 0 TO 2
++
WHILE POS 0 ISNT 0
[
SET POS 1 TO 2
>++<
SET POS 2 TO POS 0 MINUS POS 1
[->>+>+<<<]>>>[-<<<+>>>]<<[->->+<<]>>[-<<+>>]<<<
WHILE POS 1 ISNT POS 0 (POS 2 ISNT 0)
>>[<<
WHILE POS 2 ISNT 0
>>[<<
SET POS 4 TO ISZERO(POS 3)
>>>[->+>+>+<<<]>>>[-<<<+>>>]<[<->[-<->]]<+<<<<
IF ISZERO(POS 3)
>>>>[<<<<
COPY POS 1 TO POS 3
>[->>+>>+<<<<]>>>>[-<<<<+>>>>]<<<<<
END IF
>>>>-]<<<<
DECREMENT POS 2 & 3
>>->-<<<
END WHILE
>>]<<
SET POS 4 TO ISZERO(POS 3)
>>>[->+>+>+<<<]>>>[-<<<+>>>]<[<->[-<->]]<+<<<<
IF ISZERO(POS 3)
>>>>[<<<<
RESET POS 1
>[-]<
COPY POS 0 TO POS 1
[->+>+<<]>>[-<<+>>]<<
DECREMENT POS 1
>-<
SET POS 5 TO MINUS 1 AS A FLAG
>>>>>-<<<<<
END IF
>>>>-]<<<<
RESET POS 3
>>>[-]<<<
INCREMENT POS 1
>+<
SET POS 2 TO POS 0 MINUS POS 1
[->>+>+<<<]>>>[-<<<+>>>]<<[->->+<<]>>[-<<+>>]<<<
END WHILE
>>]<<
RESET POS 1
>[-]<
INCREMENT FLAG AT POS 5
>>>>>+<<<<<
IF FLAG
>>>>>[<<<<<
OUTPUT POS 0
.
END IF
>>>>>-]<<<<<
INCREMENT POS 0
+
END WHILE
]
++[>++<[->>+>+<<<]>>>[-<<<+>>>]<<[->->+<<]>>[-<<+>>]<[[>[->+>+>+<<<]>>>[-<<<+>>>]<[<->[-<->]]<+[<<<[->>+>>+<<<<]>>>>[-<<<<+>>>>]<-]<<->-<]>[->+>+>+<<<]>>>[-<<<+>>>]<[<->[-<->]]<+[<<<[-]<[->+>+<<]>>[-<<+>>]<->>>>-<-]<[-]<<+<[->>+>+<<<]>>>[-<<<+>>>]<<[->->+<<]>>[-<<+>>]<]<[-]>>>>+[<<<<<.>>>>>-]<<<<<+]
@olligobber
Copy link
Author

Cheaty version:

++.+.++.++.++++.++.++++.++.++++.++++++.++.++++++.++++.++.++++.++++++.++++++.++.++++++.++++.++.++++++.++++.++++++.++++++++.++++.++.++++.++.++++.++++++++++++++.++++.++++++.++.++++++++++.++.++++++.++++++.++++.++++++.++++++.++.++++++++++.++.++++.++.++++++++++++.++++++++++++.++++.++.++++.++++++.++.++++++++++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment