User:Laclale/AsciiSquish

From Esolang
Jump to navigation Jump to search
local tabledef=["+","-",">","<",",",".","[","]"]
--[[
ASCIIfuck is a variation of brainfuck by User:ChuckEsoteric08 which uses ASCII values of a characters.

Take ASCII value of character
If it has three digits, add first two
First digit of an operation represents brainfuck command like that:
1 is +
2 is -
3 is >
4 is <
5 is ,
6 is .
7 is [
8 is ]
Anything else is invalid
Second represents how many times command is repeated.

11	0x0b	VT 110	0x6e	n
12	0x0c	FF 120	0x78	x
13	0x0d	CR
14	0x0e	SO
15	0x0f	SI
16	0x10	DLE
17	0x11	DC1
18	0x12	DC2
19	0x13	DC3
21	0x15	NAK
22	0x16	SYN
23	0x17	ETB
24	0x18	CAN
25	0x19	EM
26	0x1a	SUB
27	0x1b	ESC
28	0x1c	FS
29	0x1d	GS
31	0x1f	US
32	0x20	SPC
33	0x21	!
34	0x22	"
35	0x23	#
36	0x24	$
37	0x25	%
38	0x26	&
39	0x27	'
41	0x29	)
42	0x2a	*
43	0x2b	+
44	0x2c	,
45	0x2d	-
46	0x2e	.
47	0x2f	/
48	0x30	0
49	0x31	1
50	0x32	2
51	0x33	3
52	0x34	4
53	0x35	5
54	0x36	6
55	0x37	7
56	0x38	8
57	0x39	9
58	0x3a	:
59	0x3b	;
61	0x3d	=
62	0x3e	>
63	0x3f	?
64	0x40	@
65	0x41	A
66	0x42	B
67	0x43	C
68	0x44	D
69	0x45	E
71	0x47	G
72	0x48	H
73	0x49	I
74	0x4a	J
75	0x4b	K
76	0x4c	L
77	0x4d	M
78	0x4e	N
79	0x4f	O
81	0x51	Q
82	0x52	R
83	0x53	S
84	0x54	T
85	0x55	U
86	0x56	V
87	0x57	W
88	0x58	X
89	0x59	Y
]]
local function squish_sub(text,n,p)
	--repeat of same letter
	local len,ref=#text,""
	local lrp,lmd=math.floor(len/9),len%9
	local lrpc,lmdc=n*10+9,n*10+lmd
	if lrp>0 then
		ref=ref..string.rep(string.char(lrpc), lrp)
	end
	ref=res..string.char(lmdc)
	return ref
end
function squish(code,table)
	local res=code
	if not table then
		table=tabledef
	end
	for i,m in ipairs(table) do
		res=string.gsub(res, m.."+", function(t)
			squish_sub(t,i,m)
		end)
	end
	return res
end