Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bennydictor/054c7cc4a72211c4df4fa7c727c770a7 to your computer and use it in GitHub Desktop.
Save bennydictor/054c7cc4a72211c4df4fa7c727c770a7 to your computer and use it in GitHub Desktop.
=== gen.py ===
#!/usr/bin/python3
def glob_format(s):
g = globals().copy()
if 'n' in g:
g['n_inc'] = (g['n'] + 1) % 256
g['n_dec'] = (g['n'] - 1) % 256
g['n_c'] = chr(g['n'])
if 'c' in g:
g['c_n'] = g['c']
g['c'] = chr(g['c'])
return s.format(**g)
printg = lambda s: print(glob_format(s))
# ∆ - rule separator
# Before:
# 〈code∴input〉
printg('〈,+++.∴A〉')
#printg('〈++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.∴〉')
# init
# ∈∫d∫∫a∫∫t∫∫a∫⊗code⊘∫m∫∫o∫∫r∫∫e∫⊥input⊤output∋
# ⊕ - pause execution
printg('〈∆∈∫0∫⊗')
printg('∴∆⊘⊥')
printg('〉∆⊤∋')
# [ do
print('do')
for n in range(1, 256):
printg('∫{n}∫⊗[]∆∫{n}∫⊗[]')
for n in range(1, 256):
for i in '+-<>,.[]':
printg('∫{n}∫⊗[{i}∆∫{n}∫⊕∀[⊛⋊{i}')
printg('⊛⋊[∆⊛⊛[⊲⋈')
printg('⊛⊛⋊]∆⊛]⊲⋈')
for i in '+-<>,.':
printg('⊛⋊{i}∆⊛{i}⊲⋈')
for i in '+-<>,.[]':
printg('⊛{i}⊲∆{i}⊲⊛')
for i in '+-<>,.[]':
for i1 in '+-<>,.[]':
printg('{i1}{i}⊲∆{i}⊴{i1}{i}')
for i in '+-<>,.[]':
for i1 in '+-<>,.[]':
printg('{i1}{i}⊴∆{i}⊴{i1}')
for i in '+-<>,.[]':
printg('∀{i}⊴∆{i}∀⊳')
for i in '+-<>,.[]':
printg('⊳{i}∆{i}⊳')
printg('⊳⊛∆⊛⊳')
printg('⊳⋈∆⋊')
printg('⊛⋊]∆⋑]')
for i in '+-<>,.[]':
printg('{i}⋑∆⋑{i}')
printg('∀⋑∆⋑')
printg('⊕⋑∆⊗')
# +
for n in range(256):
printg('∫{n}∫⊗+∆∫{n_inc}∫⊗')
# -
for n in range(256):
printg('∫{n}∫⊗-∆∫{n_dec}∫⊗')
# >
printg('⊗>∆⊕≔')
for i in '+-<>,.[]':
printg('≔{i}∆{i}≔')
printg('≔⊘⊥∆≔⊘∫0∫⊥')
for n in range(256):
printg('≔⊘∫{n}∫∆∫{n}∫≕⊘')
for n in range(256):
for i in '+-<>,.[]':
printg('{i}∫{n}∫≕∆∫{n}∫≕{i}')
for n in range(256):
printg('⊕∫{n}∫≕∆∫{n}∫⊗')
# <
for n in range(256):
printg('∫{n}∫⊗<∆⊕≻∫{n}∫')
for n in range(256):
for i in '+-<>,.[]':
printg('≻∫{n}∫{i}∆{i}≻∫{n}∫')
for n in range(256):
printg('≻∫{n}∫⊘∆≺⊘∫{n}∫')
for i in '+-<>,.[]':
printg('{i}≺∆≺{i}')
printg('⊕≺∆⊗')
# ,
printg('⊗,∆⊕⊆')
for i in '+-<>,.[]':
printg('⊆{i}∆{i}⊆')
printg('⊆⊘∆⊘⊆')
for n in range(256):
printg('⊆∫{n}∫∆∫{n}∫⊆')
for c in range(32, 256):
printg('⊆⊥{c}∆{c}⊇⊥')
for n in range(256):
for c in range(32, 256):
printg('∫{n}∫{c}⊇∆{c}⊇∫{n}∫')
for c in range(32, 256):
printg('⊘{c}⊇∆{c}⊇⊘')
for i in '+-<>,.[]':
for c in range(32, 256):
printg('{i}{c}⊇∆{c}⊇{i}')
for n in range(256):
for c in range(32, 256):
printg('∫{n}∫⊕{c}⊇∆∫{c_n}∫⊗')
# .
for c in range(32, 256):
printg('∫{c_n}∫⊗.∆∫{c_n}∫⊕⊱∫{c_n}∫')
for i in '+-<>,.[]':
for c in range(32, 256):
printg('⊱∫{c_n}∫{i}∆{i}⊱∫{c_n}∫')
for c in range(32, 256):
printg('⊱∫{c_n}∫⊘∆⊘⊱∫{c_n}∫')
for n in range(256):
for c in range(32, 256):
printg('⊱∫{c_n}∫∫{n}∫∆∫{n}∫⊱∫{c_n}∫')
for c in range(32, 256):
printg('⊱∫{c_n}∫⊥∆⊥⊱∫{c_n}∫')
for n in range(32, 256):
for c in range(32, 256):
printg('⊱∫{c_n}∫{n_c}∆{n_c}⊱∫{c_n}∫')
for c in range(32, 256):
printg('⊱∫{c_n}∫⊤∆⊤⊱∫{c_n}∫')
for c in range(32, 256):
printg('⊱∫{c_n}∫∋∆⊰{c}∋')
for c in range(32, 256):
printg('{c}⊰∆⊰{c}')
printg('⊤⊰∆⊰⊤')
printg('⊥⊰∆⊰⊥')
for n in range(256):
printg('∫{n}∫⊰∆⊰∫{n}∫')
printg('⊘⊰∆⊰⊘')
for i in '+-<>,.[]':
printg('{i}⊰∆⊰{i}')
printg('⊕⊰∆⊗')
# [ skip
printg('∫0∫⊗[∆∫0∫⊕⊙⊭')
printg('⊙⊭[∆⊙⊙⊭')
printg('⊙⊭]∆⊭')
for i in '+-<>,.':
printg('⊙⊭{i}∆⊙⊭')
printg('⊕⊭∆⊗')
# end
for n in range(256):
printg('⊗⊘∫{n}∫∆⊗⊘')
for n in range(256):
printg('∫{n}∫⊗⊘∆⊗⊘')
printg('∈⊗⊘⊥∆⋙')
for c in range(32, 256):
printg('⋙{c}∆⋙')
printg('⋙⊤∆⋧')
for c in range(32, 256):
printg('⋧{c}∆{c}⋧')
printg('⋧∋∆')
=== markov.hs ===
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (round, interact, lines, drop, concat, length, putStrLn, getContents)
import Data.Text (replace, breakOn, Text, lines, drop, snoc, isInfixOf, append, concat, length, pack)
import Data.Text.IO (interact, putStrLn, getContents)
import Data.List (foldl')
round :: Text -> [(Text, Text)] -> Text
round s [] = s
round s ((f, t):rs) = if isInfixOf f s
then let (a, b) = breakOn f s
in concat [a, t, (drop (length f) b)]
else round s rs
transform :: Text -> [(Text, Text)] -> IO ()
transform s rs = let s' = round s rs
in putStrLn s >> if s == s'
then return ()
else transform s' rs
split :: Text -> Text -> (Text, Text)
split a b = let (c, d) = breakOn a b
in (c, drop 1 d)
run :: Text -> IO ()
run file = let (s:rs) = lines file
wrs = fmap (split "∆") rs
in transform s wrs
main :: IO ()
main = getContents >>= run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment