Skip to content

Instantly share code, notes, and snippets.

@carlosefr
Last active March 23, 2020 11:11
Show Gist options
  • Save carlosefr/87608af20ab1b4cf92d141615b7ec01b to your computer and use it in GitHub Desktop.
Save carlosefr/87608af20ab1b4cf92d141615b7ec01b to your computer and use it in GitHub Desktop.
2020-4-fragmented-ce46c1c5 (brainfuck step)
#!/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)
#!/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)
----[---->+<]>++.-[-->+<]>.>-[--->+<]>--.[->+++++++<]>.--.>-[--->+<]>---.-[->+
>-[--->+<]>.------------.+++.--------.>++++++++++.-[->+++++<]>...............+
.]>-.+[->+++<]>.++++++++++++.--.--------.--[--->+<]>-.---[->++++<]>.-----.[-.+
+<+++.+++++.-------.-[--->+<]>--.[->+++<]>+.-[->+++<]>.[-->+++++++<]>.----.-.+
>++---.+++++.-[--->+<]>++.---[->+++<]>.--[--->+<]>-.---[->++++<]>-.---.---+-.<
]>+-+++<]>.-----------.+++++++++++++.---------.[--->+<]>---.[---->+<]>+++-+>.]
<-.-++++<]>.------------.---.--[--->+<]>-.---[->++++<]>-.---.-------.---.-++.>
+--->++++++.-----------.+++.---.+++++++++++++.[----->++<]>.-------------[-.<.+
+---->+--.++++.-----.+.[--->+<]>----.+[-->+<]>+.>++++++++++.[->+++<]>+.---+]..
>[----+->.[--->+<]>++.---------.++++.--------.-[->+++<]>.------------+-->.+>.>
-----[+-]--[--->+<]>---.-------.++++.-..---------.+++++++++.[-->+<]>..[.+-+-.-
[---[-+-<.>+<]>-.++++++++.+++++++++++.+[->+++<]>++.++++++++.+++++.[+-.-++-+-.[
+.--+-+-++-+.-[--->+<]>+.+++.-----------.+++++++++++++.---.+++.[---+[--+<-+-.-
+>--.-+-+>->[--->+<]>.--[--->+<]>---.-----.[->++++++<]>.+[->+++<]>-+---.]-.-.-
+]-->..-+]-]->.------------.+.+++++++++.--------------.[->+++<]>>+-+-[>+>-[-.-
.<--]---+<-<>].+[--->+<]>.[------>+<]>.--.------.--[--->+<]>-.-+.+-.--+++--..>
-+-.<---++-+.<--[->+++++<]>-.---[->++++<]>.-----.[--->+<]>-----.++->>-++..-+.+
-+--+>>->+-+-+-.++.+[---->+<]>+++.++[->+++<]>.++++++++++++.----+++>++><+-+-+.<
>+--+]]--+[>>+-++>---<]>.>++++++++++..>-[--->+<]>-.[---->+++-.-[++++++][-+-+.]
]>--+<<--++-]+-+++++<]>.++++++.+++.++++++++.+[---->+<]>+++.+.+--+<++<+>-[.>+>>
<-->+++.[>.[<+-++++.--[->+++<]>-.[->+++++++<]>.++++++.[---[+-[.-+]<+]+->--+++-
+[.]+>+-.->++>-++[>->+<]>--.---------..-[--->+<]>.-[---->>-<--+-+>]+><-+--<[+.
>+-<>-+---]++--+++-.-+.----------.++++++.---.[-->+++++<]++-].>+>++>+-].+-[]-+[
-.-+-->.--<.+[-..+[-->->+<]>++++.+[->+++<]>.+++++++++++><<->[+++++.+->++-->>+-
->->---+-[+-+--++.+>-]-.-------------.+++++++++++.-.++.+]]>--+.+++-+..+<--+++-
[]>-[[->>.+>+--++++][<->+++<]>+.--.----------.+++++.-+-+>>+.>+[<+.-++[+]>-+++-
-<]-..[]]>+]>--+++.<-+[]++.-------.+++++++++++..-----.-++.<-+<-]++-++-+>+>+++>
.+<-+--<<]+<-.-+.+++.+.<>+]>+.+++++++++++++.+++++.+--+-.+[]-+]->++-.+-+.<+.<++
->+[+-.++<++[>-++.++-+-+-+<++.-----.[->+++++<]>-.[+--+-+.->-+>>-++-[+-+>]<-]+<
-->->-+>>+>>-].++-++-+-+[+++-->+<]>+.-[->+++<]>-.-+--..[+>-.+++..+--+>++>]->+]
----]->--+--.<+++->+->>>-++.-++.+++.+.++++++++.-+>+.-[+-[+.-+.++++->++.+->[..>
.--.<-]-->---+>++-]+--]--.++[+++++++.++++++.[---++.+--+--+.-<++..[-+++-+.--+.+
-[-++-<---[--+].+.<>-[<-->>++++[->+++++<]>-.----++[+.-+->+-[].+++--+.<-+..>+[+
-+[>+-+-[[-[-+<++++---+-.]-+.++.<]>-.----[->+---++-+--+-+<[->++[+>-+-].++[++-+
-.-]>-+-.+--->++++>--->--<[++++-+>+<]>++.[->+[>-+<>+[-+-+]---+<-++-<->-++-++>+
---<-->[++.--->>++-[-.-->+.+>+.->--->+<]>--++-+-+]++->+>+>>-.+]>++-].+-++-+++.
--.+-.--+++.-[-].+-+---[]+++]+-.---+++++++.++><-+>++-+++<++>-+>+[+.>-+-+[>+++>
---+->[-+++----<++-.->--<+++<.----[+<]>.>+++<+]-++++-<+<].++-+++-<-+-.-+-+<.+-
--->[]+.+.+--.-+++-+-][-+>++++---[-+-+++++.<]+>-..<+>]+]>++<-+++>][+-[-+>+]-+[
----.<.++->--+-+>+[+-<-->->+++--[--+-+ .+++]>++-++]++>+>.[+][++<+>-.---.++>-+-
---->++>.>]..>-+]+.+-+>.-[].+.-.-...-++++.+>+++-++>.<++.+-+>-+.]+.-.---[++--+-
----]++]-]<-+][><+++.>.--+<>>+-+--->>++[+++-.<+.++.-]+.-+><->.->+---->--++..+-
-.--<++<.<+-+<+-++...-.>-.+]->-+.--]<+++>-[.+].-+++->+[-++].+--+<->--+.><++[<>
--.-+>>+-+>-++.[++-+---][-><[]-+------------+>+-+++--.--++>-+--+]-+[-+-+]+[-]+
.-+[+-]+->--++-+++-+--><->-+.<.+----------.++.+-+++--[--++.-+-[.>-+-.+-+><--><
->+.+[<>----++>.>+.+-[]+-]-+-+++-.------------[-+++-.--.+<.-+--+.-<--+[++]>>.]
>].+>++-----+>]+-.++--<>.<-+>+++++++++.>]<+++>--+++-->-++]>[<->+[-]>-+-<+>+++>
]<-.-+>[.---+-<+[-++>.+->+->]+++++++.--.+++.-.--+++--+>++>+-]-++-->+[<-]..++[-
<+-+-+-.>[[-+[+++-++]->-]>[-<>-[.+++>]<+>----[.++++.-++++.+>>-++>--+-]->++++--
++-+[+--]-.-..>+.-++<.--<-+[+>---[-.----------.++++-[+<++-++.-+++--+->>+++<+--
>>-+-+-><---+--+--+++>-[+-.++.+++>]<+++++>--[.+++++--<]++-++--+++..<-.+++.]+-.
---+-.-]+.--.>-+--++>]--+-+>]<+++>-[-.+>]<+++>-[---.>]>++[++--<.+[+]>+<.+-><>-
---+.-[<+>-->]-+--++-<[-+[--.---.------------.>]<++++>++.-++--]-<-+>+[].+-.]+[
---+.>.++]>.]<[+>-++-+..>-[+.+++++++.+++++++++++++.+.+++--+<-->-]-+.<->-+-+><-
[[-++]->><]><+-+]-..-+>---.------------.>]<++++>-[---.++--+]-...>-+[]---+..+]>
---++<---+<]+>.+<->+[+]<+++++>-[-.-.++++++.----------..+.>+>-+--->+->-.[+--+>+
>.-+>+---++<>--++-]+.>-[+++.--->]<+>---[.-------.----.+++++--+--.++-->+-+--+++
.+-+]>>-[+>+---.>-<>++..+>]<+++>-[+.++.->]<++++>-[---.->]<..-+-[><+-.++-+--.++
>+-.<-][->-+---+-.+]<+++>-[+.>]<+>-----[--.->]<++>-------[.--+--+].>+++>.--[.+
]+--+-<-.--+-[-+-+>-----[+.->]<+>---[--.++.------.-------.---+--+>-+++++----+<
<>.-+-+-+[-+[--+-++.++++++++.++>]<+++>-[+.->]<+>---[--.---.--+.-+--+++++--->+]
+]>-+[>.>+[>-.-+[.+.+>]<+++>-[+.->]<+>---[-.----------.+++++++[>+-.<+<[+.-.++>
+<]->-->]+.-.--++++.->]<+>------[+.>]<+++++>--[--.----->]<+>---++.-]+]-<+-++++
>+<----]<+-[>--.+++.------------.-->]<+>---[--.+>]<+++>-[++.->]<+-->[>>]+-+++.
->+.[.-<++--]--------.+++++++++.>]<+++>-----[.-->]<+>---[->..++++--+-.+>+-+<++
--+>.+[++.--<+++++>--[--.->]<+>---[--.---.------------.>]<++++>-[--+>-+.+-+].+
-->].+.+>---.-->]<+>---[.---------.>]<+++>-[+++++.->]<+>---[--.----.+-+[+.+>-+
---<+.-+-------.+++++++++++++.-----------.>]<++++>---[+.>]<+++++>--[+-<-+-.+-+
---+++->[.++++++.++>]<+>---[-.>]<++>-[++++.-->]<+>---[.---------.>]<+-]-+--.-+
[[-++>--+++.+++>]<+>----[.--->]<+>---[.---------.+++++++++++++.------->-+[--.+
++->+]-[++++.--.++++++.++>]<+>---[-.>]<++>-[++++.-->]<+>---[.---------.>+-[-[+
+.--+<-----.+++++++++++++.-----------.>]<++++>---[+.>]<+++++>--[.++>]<+++--[-+
.-[-++++>-[++++.---.++++++.----.->]<++++>-[---.------------.+>]<--->++[-.----+
+.--++++>.+++>]<+>--[.-.++++++.-----------.-->]<+>---[-.+>]<+++>-[+.->]<+>-->+
+--[-.->]<+>---[-.--------.---------.++++++.++++++++++++.>]<+++>-[+.-->]<+>-++
+--.->]<+++++>-[-.-.++++++.-----------.++++++.+++++++++.>]<+++>-[+++..->]<+>+.
+->]<+>---[.---------.+++++++++++++.-----------.----.>]<+++++++>--[.+++>]<+++-
+.+.------------.+++++++++++.--------------.>]<+++>-[---.++++>]<+>---[.++.+++.
@carlosefr
Copy link
Author

carlosefr commented Mar 23, 2020

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.

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