Git Product home page Git Product logo

brainfuck's Introduction

Brainfuck Playarea

Repo containing bits of Brainfuck I've written for fun.

Luhn Algorithm

To see if I could implement something real in Brainfuck I implemented the Luhn Algorithm. This takes an ID number such as a credit card number as imput at validates whether or not the number is valid according to the Luhn algorithm outputting "VALID" or "INVALID".

Full Program

>,[>,]<                                                                                            # READ CARD NUMBER
[                                                                                                  # LOOP OVER INPUT DIGITS BACKWARDS
    ------------------------------------------------                                               # CONVERT ASCCI TO DECIMAL
    >[>>+<<-]>>>>++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>[-]<<<[<<<+>>>-]>>                    # DEVIDE N BY 2 TO CALCULATE REMAINDER TO DETERMINE ODD/EVEN
    [                                                                                              # IF N IS ODD ENTER LOOP
        <<<<<<[>>>>>>>+>+<<<<<<<<-]>>>>>>>[>>+<<-]>[>+<-]>                                         # DOUBLE CARD DIGIT
        >>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]                                            # DEVIDE DOUBLED VALUE BY 10
        >>>>[<<<<<<<<<<<<<+>>>>>>>>>>>>>-]<[<<<<<<<<<<<<+>>>>>>>>>>>>-]<[-]<[-]                    # ADD TENS AND REMAINDER TOGETHER TO FORM NEW VALUE
        <<<<-
    ]
    <<<<<+                                                                                         # INCREMENT N
    <[>>+<<-]                                                                                      # ADD DIGIT VALUE TO SUM
    >[<+>-]>[<+>-]<<<                                                                              # MOVE N & SUM LEFT SINCE WE'VE PROCESSED 1 INPUT DIGIT
]                                                                                                  # CONTINUE LOOP UNTIL WE'VE PROCESSED ALL INPUT DIGITS AND WE'RE BACK AT CELL 0 WIN N IN CELL 1 AND SUM IN CELL 2
>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]                                                  # DEVIDE SUM BY 10
>>>[[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.[-]]        # IF THERE WAS A REMAINDER PRINT "IN"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.            # PRINT "V"
---------------------.                                                                             # PRINT "A"
+++++++++++.                                                                                       # PRINT "L"
---.                                                                                               # PRINT "I"
-----.                                                                                             # PRINT "D"

Full Program Minified

>,[>,]<[------------------------------------------------>[>>+<<-]>>>>++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>[-]<<<[<<<+>>>-]>>[<<<<<<[>>>>>>>+>+<<<<<<<<-]>>>>>>>[>>+<<-]>[>+<-]>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>[<<<<<<<<<<<<<+>>>>>>>>>>>>>-]<[<<<<<<<<<<<<+>>>>>>>>>>>>-]<[-]<[-]<<<<-]<<<<<+<[>>+<<-]>[<+>-]>[<+>-]<<<]>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>[[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.[-]]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------------------.+++++++++++.---.-----.

Testing

Can test brainfuck with this interpreter here

brainfuck's People

Contributors

jstringer1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.