Uh oh!
There was an error while loading. Please reload this page.
forked from Maxoplata/StringToINTERCAL
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringToINTERCAL.py
More file actions
Latest commit
73 lines (49 loc) · 1.51 KB
/
Copy pathStringToINTERCAL.py
File metadata and controls
73 lines (49 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""
StringToINTERCAL.py
Converts a string to an INTERCAL script that will output said string.
usage: python StringToINTERCAL.py your string here
https://www.maxodev.org
https://github.com/Maxoplata/StringToINTERCAL
"""
importsys
__author__="Maxamilian Demian"
__email__="max@maxdemian.com"
# class definition
classStringToINTERCAL:
politeCount=0
defpoliteLine(self, line):
ifself.politeCount==3:
self.politeCount=0
return'PLEASE {}\n'.format(line)
self.politeCount+=1
return'DO {}\n'.format(line)
defleadingZeros(self, dec):
count=len(dec)
ifcount<8:
dec= ('0'* (8-count)) +dec
returndec
defconvertToINTERCAL(self, string):
# reset politeCount
self.politeCount=0
ret=self.politeLine(',1 <- #{}'.format(len(string)))
lastCharLoc=256
foriinrange(0, len(string)):
charLoc=int(self.leadingZeros('{0:b}'.format(ord(string[i])))[::-1], 2)
movePosition=0
ifcharLoc<lastCharLoc:
movePosition= (lastCharLoc-charLoc)
elifcharLoc>lastCharLoc:
movePosition= (256-charLoc) +lastCharLoc
lastCharLoc-=movePosition
iflastCharLoc<1:
lastCharLoc=256+lastCharLoc
ret+=self.politeLine(',1 SUB #{} <- #{}'.format((i+1), movePosition))
ret+=self.politeLine('READ OUT ,1')
ret+=self.politeLine('GIVE UP')
returnret
# 1337 codez
iflen(sys.argv) >1:
inputString=' '.join(sys.argv[1:])
myINTERCAL=StringToINTERCAL()
print(myINTERCAL.convertToINTERCAL(inputString))