Skip to content

Instantly share code, notes, and snippets.

@agoldstein03
Last active November 2, 2020 02:42
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 agoldstein03/f8bd4270630bbfafa306231feb3bfcbc to your computer and use it in GitHub Desktop.
Save agoldstein03/f8bd4270630bbfafa306231feb3bfcbc to your computer and use it in GitHub Desktop.
Solution to ACSL 2019-2020 Contest #3 Intermediate Division - Veitch (written in Brainf**k)
+++++
[
>
+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+
>>>>>>>>>>>>>>>>>>>>
+
[>,[->+>+<<]>>[-<<+>>]<---------->+<[>-<[-]]>[-<<[-]>>]<<]
<[<]
>-
>
[
[-<+<+>>]<<[->>+<<]>
<<
++++++[>+++++++<-]>+
[->-<]+>[<-]<[-<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<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<<<<<<<<<<-]>
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]>
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>
[->+>+<<]>>[-<<+>>]
++++++[>++++++++<-]
<
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]
>>.
>
[->+>+<<]>>[-<<+>>]
++++++[>++++++++<-]
<
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]
>>.
>
[->+>+<<]>>[-<<+>>]
++++++[>++++++++<-]
<
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]
>>.
>
[->+>+<<]>>[-<<+>>]
++++++[>++++++++<-]
<
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]
>>.
[-]<
++++++++++.[-]<
[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[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>++<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>[-
>+>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+
<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+
>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<
[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+
<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[-
>>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+<<
]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>
+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.[-]<+++++++
+++.[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-
]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<
[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<-]
import re
A = 0b1100110011001100
B = 0b1111111100000000
C = 0b0110011001100110
D = 0b0000111111110000
gridDict = {'A' : A, '~A' : ~A, 'B' : B, '~B' : ~B, 'C' : C, '~C' : ~C, 'D' : D, '~D' : ~D}
def evalGrid(gridString):
tokens = gridString.split('+')
orGrid = 0x0000
for token in tokens:
andGrid = 0xFFFF
terms = re.findall('\~?[A-D]', token)
for term in terms:
andGrid &= gridDict[term]
orGrid |= andGrid
return orGrid
def stringEvalGrid(gridString):
return hex(evalGrid(gridString))[2:].upper().zfill(4)
inputs = [input() for i in range(5)]
for input in input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-]>[-
>+>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+
<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+
>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<
[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+
<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[-
>>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+<<
]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>
+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.[-]<+++++++
+++.[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-
]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<
[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<-]'''
programArray = [char for char in program]
length = len(programArray)
dataArray = [0 for i in range(100)]
programPointer = 0
dataPointer = 0
theInput = "\n".join([input() for i in range(5)])+"\n"
inputPointer = 0
output = ""
while (programPointer < length):
command = programArray[programPointer]
if command == ">":
dataPointer += 1;
elif command == "<":
dataPointer -= 1;
elif command == "+":
dataArray[dataPointer] += 1;
elif command == "-":
dataArray[dataPointer] -= 1;
elif command == ".":
output += chr(dataArray[dataPointer]);
elif command == ",":
dataArray[dataPointer] = ord(theInput[inputPointer]);
inputPointer += 1
elif command == "[":
if dataArray[dataPointer] == 0:
parens = 0
tempPointer = programPointer + 1
while not (programArray[tempPointer] == "]" and parens == 0):
if programArray[tempPointer] == "]":
parens -= 1
elif programArray[tempPointer] == "[":
parens += 1
tempPointer += 1
programPointer = tempPointer
elif command == "]":
if dataArray[dataPointer] != 0:
parens = 0
tempPointer = programPointer - 1
while not (programArray[tempPointer] == "[" and parens == 0):
if programArray[tempPointer] == "]":
parens -= 1
elif programArray[tempPointer] == "[":
parens += 1
tempPointer -= 1
programPointer = tempPointer
programPointer += 1
dataArray[dataPointer] %= 256
print(output)
@agoldstein03
Copy link
Author

agoldstein03 commented Nov 2, 2020

In order to avoid issues with ACSL, I am not attaching their problem description. However, they should have no issue with publishing just their test input data (available at http://www.datafiles.acsl.org/2020/contest3/sr-sample-input.txt):

AB+~AB+~A~B
AB~C~D+AB~CD+~A~B~CD
AB~C~D+~AB~C~D+A~B~C~D
B~D+~B~D
~A~BD+~A~B~D
B~D+~A~BD+A~B~C
~B~C+BCD+B~C~D
A~C+ACD+~A~CD
AB~D+~ABD+A~BD+~A~B~D
B~D+~A~CD+~A~B~C~D

The expected output data:

FF33
8810
9008
F00F
0033
F0B8
9699
8DD8
C3C3
F111

By their specifications, only 5 input lines should be given at a time.

The minified version should run equivalently to the original "source" file, as long as your interpreter supports line comments starting with a forward slash (if not, you can just manually delete those few lines). In case it was not obvious from the spaghettified "source" code, I did write this code by hand; no cheaty higher-level-language-to-Brainf**k compilers.

@agoldstein03
Copy link
Author

agoldstein03 commented Nov 2, 2020

I added my original solution written in Python, which the Brainf**k implementation is based on. I also added the Python version I wrote that is essentially just a basic Brainf**k interpreter written in Python that runs the Brainf**k implementation.

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