<commit_before>"""This module implements a cellular automaton, that models moving data along
the tape of a turing machine."""

from zasim.display.console import MultilineOneDimConsolePainter
from zasim.simulator import BaseSimulator
from zasim.config import RandomInitialConfiguration

palette = [["a ", "a ", "a ", "a ", "b ", "b ", "b ", "b ", "c ", "c ", "c ", "c "],
           ["  ", "<a", "<b", "<c", "  ", "<a", "<b", "<c", "  ", "<a", "<b", "<c"]]
values  =  [ 0,    1,    2,    3,    4,    5,    6,    7,    8,    9,    10,   11]
palette = MultilineOneDimConsolePainter.box_art_palette(palette)
palette = MultilineOneDimConsolePainter.convert_palette(palette, values)

print palette

class TuringTapeSimulator(BaseSimulator):
    def __init__(self):
        self.conf = RandomInitialConfiguration(12).generate((25,))

    def get_config(self):
        return self.conf

painter = MultilineOneDimConsolePainter(TuringTapeSimulator(), palette, connect=False)

painter.after_step()

<commit_msg>implement the simulator and step function<commit_after>"""This module implements a cellular automaton, that models moving data along
the tape of a turing machine."""

from zasim.display.console import MultilineOneDimConsolePainter
from zasim.simulator import BaseSimulator, TargetProxy
from zasim.config import RandomInitialConfiguration

palette = [["a ", "a ", "a ", "a ", "b ", "b ", "b ", "b ", "c ", "c ", "c ", "c "],
           ["<a", "<b", "<c", "  ", "<a", "<b", "<c", "  ", "<a", "<b", "<c", "  "]]
values  =  [ 0,    1,    2,    3,    4,    5,    6,    7,    8,    9,    10,   11]
probabs =  [0.1,   0,    0,   0.23,  0,  0.1,    0,   0.23,  0,    0,    0.1, 0.24]
palette = MultilineOneDimConsolePainter.box_art_palette(palette)
palette = MultilineOneDimConsolePainter.convert_palette(palette, values)

print palette

class TuringTapeSimulator(BaseSimulator):
    def __init__(self):
        super(TuringTapeSimulator, self).__init__()
        self.cconf = RandomInitialConfiguration(12, *probabs).generate((25,))
        self.shape = (25,)
        self.target_attrs = ["cconf"]
        self.t = TargetProxy(self, self.target_attrs)

    def get_config(self):
        return self.cconf

    def step(self):
        for index, (cell, next_cell) in enumerate(zip(self.cconf[:-1], self.cconf[1:])):
            result = cell
            if next_cell & 3 == 3:
                # if the lowest 2 bytes are 1, no information is transferred and
                # the transferal state is cleared
                result = cell | 3
            else:
                # otherwise, the information from the right is moved here
                # and the own information is transferred.
                result = (next_cell & 3) << 2 | (cell & ~3) >> 2

            self.cconf[index] = result

        self.updated.emit()

tape = TuringTapeSimulator()
painter = MultilineOneDimConsolePainter(tape, palette)

painter.after_step()
for i in range(10):
    tape.step()
    print

{'fraction_non_alphanumeric': 0.14165545087483175, 'fraction_numerical': 0.024226110363391656, 'mean_word_length': 2.861038961038961, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '218894', 'n_tokens_mistral': 1031, 'n_tokens_neox': 974, 'n_words': 269}