Last active
March 23, 2020 11:11
-
-
Save carlosefr/87608af20ab1b4cf92d141615b7ec01b to your computer and use it in GitHub Desktop.
2020-4-fragmented-ce46c1c5 (brainfuck step)
This file contains hidden or 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
#!/usr/bin/env python3 | |
grid = [] | |
with open("report.txt", "r") as f: | |
for line in f: | |
grid.append([c for c in line.strip("\n")]) | |
size = len(grid) | |
text = [] | |
x = 0 | |
y = 0 | |
x_motion = 1 | |
y_motion = 0 | |
for _ in range(size * size): | |
text.append(grid[y][x]) | |
grid[y][x] = None | |
# Turn right when blocked... | |
if not (0 <= x + x_motion < size) or not (0 <= y + y_motion < size) or not grid[y + y_motion][x + x_motion]: | |
x_motion, y_motion = { | |
(1, 0): (0, 1), | |
(0, 1): (-1, 0), | |
(-1, 0): (0, -1), | |
(0, -1): (1, 0) | |
}[(x_motion, y_motion)] | |
x += x_motion | |
y += y_motion | |
# from pprint import pprint | |
# pprint("Output: '%s'" % "".join(text)) | |
with open("answer.txt", "w") as f: | |
print("".join(text), file=f) |
This file contains hidden or 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
#!/usr/bin/env python3 | |
from math import sqrt, ceil | |
padding_character = " " | |
text = open("brainfuck.txt", "r").read().strip("\n").replace("\n", padding_character) | |
size = ceil(sqrt(len(text))) | |
grid = [[None for _ in range(size)] for _ in range(size)] | |
x = 0 | |
y = 0 | |
x_motion = 1 | |
y_motion = 0 | |
for c in text + (padding_character * (size * size - len(text))): | |
grid[y][x] = c | |
# Turn right when blocked... | |
if not (0 <= x + x_motion < size) or not (0 <= y + y_motion < size) or grid[y + y_motion][x + x_motion]: | |
x_motion, y_motion = { | |
(1, 0): (0, 1), | |
(0, 1): (-1, 0), | |
(-1, 0): (0, -1), | |
(0, -1): (1, 0) | |
}[(x_motion, y_motion)] | |
x += x_motion | |
y += y_motion | |
# from pprint import pprint | |
# pprint(grid) | |
with open("report.txt", "w") as f: | |
for line in grid: | |
print("".join(line), file=f) |
This file contains hidden or 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
----[---->+<]>++.-[-->+<]>.>-[--->+<]>--.[->+++++++<]>.--.>-[--->+<]>---.-[->+ | |
>-[--->+<]>.------------.+++.--------.>++++++++++.-[->+++++<]>...............+ | |
.]>-.+[->+++<]>.++++++++++++.--.--------.--[--->+<]>-.---[->++++<]>.-----.[-.+ | |
+<+++.+++++.-------.-[--->+<]>--.[->+++<]>+.-[->+++<]>.[-->+++++++<]>.----.-.+ | |
>++---.+++++.-[--->+<]>++.---[->+++<]>.--[--->+<]>-.---[->++++<]>-.---.---+-.< | |
]>+-+++<]>.-----------.+++++++++++++.---------.[--->+<]>---.[---->+<]>+++-+>.] | |
<-.-++++<]>.------------.---.--[--->+<]>-.---[->++++<]>-.---.-------.---.-++.> | |
+--->++++++.-----------.+++.---.+++++++++++++.[----->++<]>.-------------[-.<.+ | |
+---->+--.++++.-----.+.[--->+<]>----.+[-->+<]>+.>++++++++++.[->+++<]>+.---+].. | |
>[----+->.[--->+<]>++.---------.++++.--------.-[->+++<]>.------------+-->.+>.> | |
-----[+-]--[--->+<]>---.-------.++++.-..---------.+++++++++.[-->+<]>..[.+-+-.- | |
[---[-+-<.>+<]>-.++++++++.+++++++++++.+[->+++<]>++.++++++++.+++++.[+-.-++-+-.[ | |
+.--+-+-++-+.-[--->+<]>+.+++.-----------.+++++++++++++.---.+++.[---+[--+<-+-.- | |
+>--.-+-+>->[--->+<]>.--[--->+<]>---.-----.[->++++++<]>.+[->+++<]>-+---.]-.-.- | |
+]-->..-+]-]->.------------.+.+++++++++.--------------.[->+++<]>>+-+-[>+>-[-.- | |
.<--]---+<-<>].+[--->+<]>.[------>+<]>.--.------.--[--->+<]>-.-+.+-.--+++--..> | |
-+-.<---++-+.<--[->+++++<]>-.---[->++++<]>.-----.[--->+<]>-----.++->>-++..-+.+ | |
-+--+>>->+-+-+-.++.+[---->+<]>+++.++[->+++<]>.++++++++++++.----+++>++><+-+-+.< | |
>+--+]]--+[>>+-++>---<]>.>++++++++++..>-[--->+<]>-.[---->+++-.-[++++++][-+-+.] | |
]>--+<<--++-]+-+++++<]>.++++++.+++.++++++++.+[---->+<]>+++.+.+--+<++<+>-[.>+>> | |
<-->+++.[>.[<+-++++.--[->+++<]>-.[->+++++++<]>.++++++.[---[+-[.-+]<+]+->--+++- | |
+[.]+>+-.->++>-++[>->+<]>--.---------..-[--->+<]>.-[---->>-<--+-+>]+><-+--<[+. | |
>+-<>-+---]++--+++-.-+.----------.++++++.---.[-->+++++<]++-].>+>++>+-].+-[]-+[ | |
-.-+-->.--<.+[-..+[-->->+<]>++++.+[->+++<]>.+++++++++++><<->[+++++.+->++-->>+- | |
->->---+-[+-+--++.+>-]-.-------------.+++++++++++.-.++.+]]>--+.+++-+..+<--+++- | |
[]>-[[->>.+>+--++++][<->+++<]>+.--.----------.+++++.-+-+>>+.>+[<+.-++[+]>-+++- | |
-<]-..[]]>+]>--+++.<-+[]++.-------.+++++++++++..-----.-++.<-+<-]++-++-+>+>+++> | |
.+<-+--<<]+<-.-+.+++.+.<>+]>+.+++++++++++++.+++++.+--+-.+[]-+]->++-.+-+.<+.<++ | |
->+[+-.++<++[>-++.++-+-+-+<++.-----.[->+++++<]>-.[+--+-+.->-+>>-++-[+-+>]<-]+< | |
-->->-+>>+>>-].++-++-+-+[+++-->+<]>+.-[->+++<]>-.-+--..[+>-.+++..+--+>++>]->+] | |
----]->--+--.<+++->+->>>-++.-++.+++.+.++++++++.-+>+.-[+-[+.-+.++++->++.+->[..> | |
.--.<-]-->---+>++-]+--]--.++[+++++++.++++++.[---++.+--+--+.-<++..[-+++-+.--+.+ | |
-[-++-<---[--+].+.<>-[<-->>++++[->+++++<]>-.----++[+.-+->+-[].+++--+.<-+..>+[+ | |
-+[>+-+-[[-[-+<++++---+-.]-+.++.<]>-.----[->+---++-+--+-+<[->++[+>-+-].++[++-+ | |
-.-]>-+-.+--->++++>--->--<[++++-+>+<]>++.[->+[>-+<>+[-+-+]---+<-++-<->-++-++>+ | |
---<-->[++.--->>++-[-.-->+.+>+.->--->+<]>--++-+-+]++->+>+>>-.+]>++-].+-++-+++. | |
--.+-.--+++.-[-].+-+---[]+++]+-.---+++++++.++><-+>++-+++<++>-+>+[+.>-+-+[>+++> | |
---+->[-+++----<++-.->--<+++<.----[+<]>.>+++<+]-++++-<+<].++-+++-<-+-.-+-+<.+- | |
--->[]+.+.+--.-+++-+-][-+>++++---[-+-+++++.<]+>-..<+>]+]>++<-+++>][+-[-+>+]-+[ | |
----.<.++->--+-+>+[+-<-->->+++--[--+-+ .+++]>++-++]++>+>.[+][++<+>-.---.++>-+- | |
---->++>.>]..>-+]+.+-+>.-[].+.-.-...-++++.+>+++-++>.<++.+-+>-+.]+.-.---[++--+- | |
----]++]-]<-+][><+++.>.--+<>>+-+--->>++[+++-.<+.++.-]+.-+><->.->+---->--++..+- | |
-.--<++<.<+-+<+-++...-.>-.+]->-+.--]<+++>-[.+].-+++->+[-++].+--+<->--+.><++[<> | |
--.-+>>+-+>-++.[++-+---][-><[]-+------------+>+-+++--.--++>-+--+]-+[-+-+]+[-]+ | |
.-+[+-]+->--++-+++-+--><->-+.<.+----------.++.+-+++--[--++.-+-[.>-+-.+-+><-->< | |
->+.+[<>----++>.>+.+-[]+-]-+-+++-.------------[-+++-.--.+<.-+--+.-<--+[++]>>.] | |
>].+>++-----+>]+-.++--<>.<-+>+++++++++.>]<+++>--+++-->-++]>[<->+[-]>-+-<+>+++> | |
]<-.-+>[.---+-<+[-++>.+->+->]+++++++.--.+++.-.--+++--+>++>+-]-++-->+[<-]..++[- | |
<+-+-+-.>[[-+[+++-++]->-]>[-<>-[.+++>]<+>----[.++++.-++++.+>>-++>--+-]->++++-- | |
++-+[+--]-.-..>+.-++<.--<-+[+>---[-.----------.++++-[+<++-++.-+++--+->>+++<+-- | |
>>-+-+-><---+--+--+++>-[+-.++.+++>]<+++++>--[.+++++--<]++-++--+++..<-.+++.]+-. | |
---+-.-]+.--.>-+--++>]--+-+>]<+++>-[-.+>]<+++>-[---.>]>++[++--<.+[+]>+<.+-><>- | |
---+.-[<+>-->]-+--++-<[-+[--.---.------------.>]<++++>++.-++--]-<-+>+[].+-.]+[ | |
---+.>.++]>.]<[+>-++-+..>-[+.+++++++.+++++++++++++.+.+++--+<-->-]-+.<->-+-+><- | |
[[-++]->><]><+-+]-..-+>---.------------.>]<++++>-[---.++--+]-...>-+[]---+..+]> | |
---++<---+<]+>.+<->+[+]<+++++>-[-.-.++++++.----------..+.>+>-+--->+->-.[+--+>+ | |
>.-+>+---++<>--++-]+.>-[+++.--->]<+>---[.-------.----.+++++--+--.++-->+-+--+++ | |
.+-+]>>-[+>+---.>-<>++..+>]<+++>-[+.++.->]<++++>-[---.->]<..-+-[><+-.++-+--.++ | |
>+-.<-][->-+---+-.+]<+++>-[+.>]<+>-----[--.->]<++>-------[.--+--+].>+++>.--[.+ | |
]+--+-<-.--+-[-+-+>-----[+.->]<+>---[--.++.------.-------.---+--+>-+++++----+< | |
<>.-+-+-+[-+[--+-++.++++++++.++>]<+++>-[+.->]<+>---[--.---.--+.-+--+++++--->+] | |
+]>-+[>.>+[>-.-+[.+.+>]<+++>-[+.->]<+>---[-.----------.+++++++[>+-.<+<[+.-.++> | |
+<]->-->]+.-.--++++.->]<+>------[+.>]<+++++>--[--.----->]<+>---++.-]+]-<+-++++ | |
>+<----]<+-[>--.+++.------------.-->]<+>---[--.+>]<+++>-[++.->]<+-->[>>]+-+++. | |
->+.[.-<++--]--------.+++++++++.>]<+++>-----[.-->]<+>---[->..++++--+-.+>+-+<++ | |
--+>.+[++.--<+++++>--[--.->]<+>---[--.---.------------.>]<++++>-[--+>-+.+-+].+ | |
-->].+.+>---.-->]<+>---[.---------.>]<+++>-[+++++.->]<+>---[--.----.+-+[+.+>-+ | |
---<+.-+-------.+++++++++++++.-----------.>]<++++>---[+.>]<+++++>--[+-<-+-.+-+ | |
---+++->[.++++++.++>]<+>---[-.>]<++>-[++++.-->]<+>---[.---------.>]<+-]-+--.-+ | |
[[-++>--+++.+++>]<+>----[.--->]<+>---[.---------.+++++++++++++.------->-+[--.+ | |
++->+]-[++++.--.++++++.++>]<+>---[-.>]<++>-[++++.-->]<+>---[.---------.>+-[-[+ | |
+.--+<-----.+++++++++++++.-----------.>]<++++>---[+.>]<+++++>--[.++>]<+++--[-+ | |
.-[-++++>-[++++.---.++++++.----.->]<++++>-[---.------------.+>]<--->++[-.----+ | |
+.--++++>.+++>]<+>--[.-.++++++.-----------.-->]<+>---[-.+>]<+++>-[+.->]<+>-->+ | |
+--[-.->]<+>---[-.--------.---------.++++++.++++++++++++.>]<+++>-[+.-->]<+>-++ | |
+--.->]<+++++>-[-.-.++++++.-----------.++++++.+++++++++.>]<+++>-[+++..->]<+>+. | |
+->]<+>---[.---------.+++++++++++++.-----------.----.>]<+++++++>--[.+++>]<+++- | |
+.+.------------.+++++++++++.--------------.>]<+++>-[---.++++>]<+>---[.++.+++. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was the brainfuck step from Fragmented, the last qualifier challenge for the 2020 edition of the Pixels Camp quizshow, along with some quick and dirty code to wind and unwind text.