コード例 #1
0
def execute(filename):
    f = open(filename, "r")
    spoon = f.read()
    f.close()

    bf = spoon_to_brainfuck(spoon)
    brainfuck.evaluate(bf)
コード例 #2
0
def easter_eggs(addr):
    # Download Brainfuck and ( ͡° ͜ʖ ͡°)f**k code from page
    resp = requests.get(addr + '/?pingUrl=1.1.1.1')
    brainfuck_code = html.unescape(
        re.search(r'<b>(.*) END e', resp.text).group(1))
    lennyfuck_code = html.unescape(
        re.search(r'c END (.*)\n<\/b>', resp.text).group(1))

    # Evaluate Brainfuck code
    brainfuck.evaluate(brainfuck_code)
    print()

    # Transform ( ͡° ͜ʖ ͡°)f**k to Brainfuck (because it's easy) and evaluate created code
    changed_code = lenny_to_brain(lennyfuck_code)
    brainfuck.evaluate(changed_code)
コード例 #3
0
    def Run(self):
        code = self.textArea.get(0.0, END)
        symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '"', "'", '{', "}", '|', "/", "\ "]
        for i in code:
            if i.isdigit() or i.isalpha() is True or i in symbols:
                self.s = i 
                if self.s:
                    self.idx = '1.0'
                while 1:
                    self.idx = self.textArea.search(self.s, self.idx, nocase = 1, stopindex = END)
                    if not self.idx:break
                    self.lastidx = '%s+%dc' % (self.idx, len(self.s))
                    self.textArea.tag_add('found', self.idx, self.lastidx)
                    self.idx = self.lastidx
                self.textArea.tag_config('found', background = 'red')
                showerror("Error", "invalid syntax")
                self.textArea.tag_config('found', background = None)

        self.tabControl.select(self.tab2)
        output = brainfuck.evaluate(code)
        self.View.config(state = NORMAL)
        self.View.insert(END, str(output))#don't know why but it prints the output to your python shell instead 
        self.View.delete(0.0, END)
        self.View.insert(0.0, self.text)
        
        self.View.config(state = DISABLED)
コード例 #4
0
async def brainf(ctx, *, code):
    output = brainfuck.evaluate(code)
    embed  = Embed(title="Here is your result", color=0x00e1ff)
    embed.add_field(name="the output of your code is:", value=output, inline=False)
    embed.add_field(name="the input code was:", value="```"+code+"```", inline=False)
    embed.set_footer(text="requested by <@{}>".format(ctx.message.author.id))
    await ctx.send(embed=embed)
コード例 #5
0
ファイル: test.py プロジェクト: leoDesilva/brainfuck_compiler
import brainfuck

brainfuck.evaluate(
    "++++++[>++++++++<-]>+.[-]>++++++[<+++++++>-]<+.+++++++.+++++++++++.----------."
)
コード例 #6
0
    data = s.recv(40960).decode().strip()
    if not data:
        continue

    print("Received:", data)
    if 'Are you ready? [y/n]' in data:
        s.send(b'y\n')

    if 'FIGHT!' in data:
        while 'What value is in the ' not in data:
            data += s.recv(4096).decode().strip()

        segments = data.split("+-+-+-+-+-+-+-+-+-+-")
        code = ''.join(segments[1].splitlines())
        print('>> Code:', code)

        registers = brainfuck.evaluate(code)
        print('>> Register:', registers)

        match = re.search(r'What value is in the (\d+).. register',
                          segments[2].strip())
        numb = int(match.group(1))

        result = registers[numb - 1]
        print('>> Result:', result)

        s.send(str(result).encode() + b'\n')

    if 'GCTF' in data:
        quit()
コード例 #7
0
def get_reward(code_string):

    task = PrintTask(base=27, fixed_string=[7, 4, 11, 11, 14])  # print hello

    max_execution_steps = 5000
    require_correct_syntax = False
    io_seqs = task.make_io_set()
    terminal_reward = 0.0
    failure_reward = -2.0
    correct_bonus = 1.0
    max_code_length = 32
    min_code_length = 0
    code_length_bonus = 1.0
    reward_fn = absolute_distance_reward
    time_penalty = (1.0 / (max_code_length - min_code_length)
                    if max_code_length > min_code_length else 0.0)
    input_type = (task.input_type
                  if hasattr(task, 'input_type') else IOType.integer)
    output_type = (task.output_type
                   if hasattr(task, 'output_type') else IOType.integer)
    best_reward = compute_best_reward(task, reward_fn, correct_bonus,
                                      code_length_bonus)

    results = []
    reason = 'correct'
    for input_seq, output_seq in io_seqs:
        eval_result = bf.evaluate(
            code_string[:-1],
            input_buffer=input_seq,
            timeout=0.1,  #not send EOS to interpreter
            max_steps=max_execution_steps,
            base=task.base,
            require_correct_syntax=require_correct_syntax)
        result, success = eval_result.output, eval_result.success
        if not success:
            # Code execution timed out.
            terminal_reward = failure_reward
            results = []
            reason = eval_result.failure_reason
            break
        else:
            terminal_reward += reward_fn(result, output_seq, task.base)
            if result == output_seq:
                terminal_reward += correct_bonus  # Bonus for correct answer.
                # Only add additional reward for shorter code. Subtracting reward
                # interferes with the main objective. Only optimize for length once
                # any solution is found.
                if min_code_length == max_code_length:
                    terminal_reward += code_length_bonus
                else:
                    terminal_reward += code_length_bonus * clipped_linear(
                        x=len(code_string),
                        x0=min_code_length,
                        y0=1.0,
                        slope=-time_penalty,
                        y_range=(0.0, 1.0))

                # reason remains 'correct' if it is already
            elif reason == 'correct':
                reason = 'wrong'
        results.append(result)

    # Return list of rewards, one for each char in the code. All are 0 except
    # for the terminal reward.
    terminal_reward /= best_reward
    return RewardInfo(episode_rewards=[0.0] * (len(code_string) - 1) +
                      [terminal_reward],
                      input_case=IOTuple(i for i, o in io_seqs),
                      correct_output=IOTuple(o for i, o in io_seqs),
                      code_output=IOTuple(results),
                      input_type=input_type,
                      output_type=output_type,
                      reason=reason)
コード例 #8
0
ファイル: sayings.py プロジェクト: garyAdam/petsayings
def init():
    brainfuck.evaluate('''++++++++++++++++[>++>++>++>++>++>++>++>++>++>++>++>++>++>++>++>++>++>++>++<<<<<<<<<<<<<<<<<<<-]>>+++++++++++++++++++++++++++++++++
<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[
>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+<<<<<<<<<<<<<<<<<<<-]>>>>--->+++++++++[<]>>>>>>----------------------------->+>++++++++++++++>
+++>+++++++++++[<]>>>>>.<.<.>>>>.[<]>.[>]++++++++++<<--.>+++++++++++++++++++++.[<]>.>.>.>.>.<<<<.>>>>>.>.>.>.>.[>]<.
[<]>>>>>>>>>>>++.>+++++.>++++++++.>++++++++++++++++.<<<<<<<.>>>>>>>>++++++++++++++.<<<.>>>>++++++++++.<<<<<<<.[<]>.[>]<<<<<<<<.<.>>>>>+++++++++++++++.<<<.[>]+++++[>+++++++++<-]>+...''')
コード例 #9
0
import brainfuck
sourcecode = """
    ++++++++++[>+++++++>++++++++++>+++>+<<<<-]
    >++.>+.+++++++..+++.>++.<<+++++++++++++++.
    >.+++.------.--------.>+.>.
  """

brainfuck.evaluate(sourcecode)
コード例 #10
0
import brainfuck

bf = '+[----->+++<]>+.---.+++++++..+++.[--->+<]>----.'
print(brainfuck.evaluate(bf))  # hello!
コード例 #11
0
    return term[0] >= 'A' and term[0] <= 'Z'


def toBrainFuck(binary):
    return {
        '000': '>',
        '001': '<',
        '010': '+',
        '011': '-',
        '100': '.',
        '101': ',',
        '110': '[',
        '111': ']'
    }[binary]


index = 0
brainfuckSource = ''
for line in file(source):
    line = line.strip()
    data = line.split(' ')
    isCap1 = isCap(data[0])
    isCap2 = isCap(data[1])
    isCap3 = isCap(data[2])
    binary = '%d%d%d' % (isCap1, isCap2, isCap3)
    brainfuckCommand = toBrainFuck(binary)
    brainfuckSource += brainfuckCommand
    index += 1

brainfuck.evaluate(brainfuckSource)