GithubHelp home page GithubHelp logo

lalbi94 / z1dcellularautomata Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18 KB

Simple representation of a cellular automaton following the rules established by Stephen Wolfram.

License: MIT License

Rust 100.00%
1d automata automaton rust wolfram

z1dcellularautomata's Introduction

Z1DCellularAutomata

Simple representation of a cellular automaton following the rules established by Stephen Wolfram. This code won't show you a representation in the form of a triangle, but rather in the form of a rectangle or square.

Explanation

Choose a rule configuration rules/mod.rs:11 (i know it's hard work but until i update it'll be like this)

Binary representation State conversion
0 ALIVE.
1 DEAD.

example with rules 30 (0001 1110).

match (prev, curr, next) {
    (State::ALIVE, State::ALIVE, State::ALIVE) => State::DEAD,
    (State::ALIVE, State::ALIVE, State::DEAD) => State::ALIVE,
    (State::ALIVE, State::DEAD, State::ALIVE) => State::ALIVE,
    (State::ALIVE, State::DEAD, State::DEAD) => State::DEAD,
    (State::DEAD, State::ALIVE, State::ALIVE) => State::DEAD,
    (State::DEAD, State::ALIVE, State::DEAD) => State::ALIVE,
    (State::DEAD, State::DEAD, State::ALIVE) => State::ALIVE,
    (State::DEAD, State::DEAD, State::DEAD) => State::DEAD,
}

Now there are two solutions: either you submit a set of cellular automata to the WCAStorage constructor, or you add the automata one by one to the WCAStorage structure.

For the option n.1, create an sequence of State store in Vec<State>.

|sequence| > 3
let sequence: Vec<State> = vec![State::ALIVE,State::DEAD, ...];

Instantiate WCAStorage by giving it the list as an argument (if you have one).

let mut container: WCAStorage = WCAStorage::new(Some(sequence));

or

let mut container: WCAStorage = WCAStorage::new(None);
container.push(State::DEAD)
container.push(State::ALIVE)
...

You can now start the simulation with WCAStorage::run(n-step) -> Result<Flag, &'static str>

container.run(20) //for 20 steps.

example of automata following rules 30.

References

Licence

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

If you have any questions or encounter any issues, please open an issue on the GitHub repository at https://github.com/lalBi94/Z1DCellularAutomata/issues or send an email to [email protected].

z1dcellularautomata's People

Contributors

lalbi94 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.