Last active
November 2, 2020 02:42
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++ | |
[ | |
> | |
+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+ | |
>>>>>>>>>>>>>>>>>>>> | |
+ | |
[>,[->+>+<<]>>[-<<+>>]<---------->+<[>-<[-]]>[-<<[-]>>]<<] | |
<[<] | |
>- | |
> | |
[ | |
[-<+<+>>]<<[->>+<<]> | |
<< | |
++++++[>+++++++<-]>+ | |
[->-<]+>[<-]<[-< | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
>>>>>>>>>>>>>>>>> | |
] | |
+++[>+++++++<-]>+ | |
[->-<]+>[<-]<[-< | |
< | |
[if there was a ~ | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
[-]>[-]>>>[-]>[-]>>>[-]>[-]>>>[-]>[-]>>> | |
>>>>>>>>>>>>>>>> | |
->-< | |
] | |
>+ | |
[ | |
-< | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
>>[-]>[-]>>>[-]>[-]>>>[-]>[-]>>>[-]>[-]> | |
>>>>>>>>>>>>>>>>> | |
] | |
] | |
>>- | |
<+>[<-]<[-< | |
< | |
[if there was a ~ | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>>>>>>>>> | |
>>>>>>>>>>>>>>>> | |
->-< | |
] | |
>+ | |
[ | |
-< | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
>>>>>>>>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]> | |
>>>>>>>>>>>>>>>>> | |
] | |
] | |
>>- | |
<+>[<-]<[-< | |
< | |
[if there was a ~ | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
>[-]>[-]>>>[-]>[-]>>>[-]>[-]>>>[-]>[-]>> | |
>>>>>>>>>>>>>>>> | |
->-< | |
] | |
>+ | |
[ | |
-< | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
[-]>>>[-]>[-]>>>[-]>[-]>>>[-]>[-]>>>[-]> | |
>>>>>>>>>>>>>>>>> | |
] | |
] | |
>>- | |
<+>[<-]<[-< | |
< | |
[if there was a ~ | |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
>>>>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>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+> | |
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]> | |
[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]> | |
[->+>+<<]>>[-<<+>>] | |
++++++[>++++++++<-] | |
< | |
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]] | |
>>. | |
> | |
[->+>+<<]>>[-<<+>>] | |
++++++[>++++++++<-] | |
< | |
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]] | |
>>. | |
> | |
[->+>+<<]>>[-<<+>>] | |
++++++[>++++++++<-] | |
< | |
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]] | |
>>. | |
> | |
[->+>+<<]>>[-<<+>>] | |
++++++[>++++++++<-] | |
< | |
[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]] | |
>>. | |
[-]< | |
++++++++++.[-]< | |
[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]< | |
- | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++[>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>>>>>>>>>>>>>>>>>>>+[>,[->+>+<< | |
]>>[-<<+>>]<---------->+<[>-<[-]]>[-<<[-]>>]<<]<[<]>->[[-<+<+>>]<<[->> | |
+<<]><<++++++[>+++++++<-]>+[->-<]+>[<-]<[-<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
<<<<<<[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<< | |
<<<<<<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>>>>>>>>> | |
>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+ | |
>[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<<<<<<< | |
<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>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<<<<<-]>[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>++< | |
<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>>>++++++ | |
++<<<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>[>>>>>>>>>> | |
>>>>++<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>> | |
>++++++++<<<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<<-]>[>>> | |
>>>>>>>>>>>++<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>[>>>>>>>> | |
>>>>>>>>++++++++<<<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>>>++++<<<<<<<<<<<<<<< | |
-]>[>>>>>>>>>>>>>>++<<<<<<<<<<<<<<-]>[>>>>>>>>>>>>>+<<<<<<<<<<<<<-]>[- | |
>+>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+ | |
<<[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+ | |
>+<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<< | |
[->>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+ | |
<<]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[- | |
>>+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.>[->+>+<< | |
]>>[-<<+>>]++++++[>++++++++<-]<[->>+<<[->>+<<[->>+<<[->>+<<[->>+<<[->> | |
+<<[->>+<<[->>+<<[->>+<<[->>++++++++<<[->>+<<]]]]]]]]]]]>>.[-]<+++++++ | |
+++.[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[- | |
]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]< | |
[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<-] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 inputs: | |
print(stringEvalGrid(input)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program = '''+++++[>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>>>>>>>>>>>>>>>>>>>+[>,[->+>+<< | |
]>>[-<<+>>]<---------->+<[>-<[-]]>[-<<[-]>>]<<]<[<]>->[[-<+<+>>]<<[->> | |
+<<]><<++++++[>+++++++<-]>+[->-<]+>[<-]<[-<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
<<<<<<[>>>>>>>>>>>>>>>>[-]+<<<<<<<<<<<<<<<<-]+>[>>>>>>>>>>>>>>>>[-]+<< | |
<<<<<<<<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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) |
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
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):
The expected output data:
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.