Advertisement
Guest User

Brainfuck and Wordfuck conversion (final)

a guest
Aug 23rd, 2014
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. #Pass programs to these functions in the form of strings. wf_bf will accept Wordfuck and return Brainfuck while bf_wf
  2. #will accept Brainfuck and return Wordfuck, generated with a list of random words.
  3. def words(s):
  4.     result,z=[],s
  5.     while len(z)>0:
  6.         try:
  7.             x=z.index(' ')
  8.             result.append(z[:x])
  9.             z=z[x+1:]
  10.         except:
  11.             result.append(z)
  12.             z=''
  13.     for i in result:
  14.         if i=='':
  15.             result.remove(i)
  16.     return result
  17.    
  18. def wf_bf(s):
  19.     table={2:'.',3:'-',4:'+',5:',',6:'>',7:'<',8:'[',9:']'}
  20.     z=words(s)
  21.     result = ""
  22.     for i in z:
  23.         if len(i) in [2,3,4,5,6,7,8,9]:
  24.             result+=table[len(i)]
  25.     return result
  26.  
  27.  
  28. def bf_wf(s):
  29.     from random import choice
  30.     randomwords=[['it', 'to', 'is', 'or', 'be', 'ye', 'so', 'me', 'he', 'pi', 'do', 'we', 'my'], ['not', 'man', 'and', 'ore', 'try', 'men', 'the', 'you', 'was', 'can', 'bat', 'dry', 'dog', 'ran', 'nor', 'cat', 'thy', 'pit', 'bin', 'box', 'rat', 'mat', 'fat', 'hat', 'ham', 'dam', 'fan', 'joy', 'tin', 'toy', 'gag', 'pan', 'pad', 'pin', 'cry'], ['dart', 'that', 'list', 'once', 'fish', 'leaf', 'pine', 'grin', 'cola', 'loop', 'colt', 'plan', 'pore', 'play', 'nick', 'dent', 'lick'], ['mouse', 'among', 'spike', 'woman', 'women', 'brain', 'novel', 'there', 'named', 'sloth', 'zebra', 'throw', 'foyer', 'lucky', 'horse', 'block', 'truck', 'canal', 'radio', 'break', 'biome'], ['roller', 'sailor', 'botany', 'bonobo', 'portal', 'pocket', 'tactic', 'jumped', 'remote'], ['octopus', 'cranium', 'blanket', 'filings', 'bemused', 'machine', 'sawdust', 'gymnast', 'beastly', 'testify', 'dubious', 'coastal'], ['question', 'critical', 'hospital', 'trifling', 'alphabet', 'lodgings', 'imposter', 'screamer', 'apparent', 'omnivore', 'dramatic', 'dissolve', 'ordinary', 'syllable', 'humanity', 'hydrogen'], ['limousine', 'enlighten', 'vengeance', 'furniture', 'candlelit', 'predicted', 'apathetic', 'statuette', 'climactic', 'allergens', 'dexterity', 'versatile']]
  31.     table={'.':2,'-':3,'+':4,',':5,'>':6,'<':7,'[':8,']':9}
  32.     result=""
  33.     for i in s:
  34.         if i in '><+-.,[]':
  35.             result+=choice(randomwords[table[i]-2])+" "
  36.     return result[:-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement