Skip to main content
Commonmark migration
Source Link

##Lua, 121 Bytes. function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end

Lua, 121 Bytes.

##Explained function g(s) print( -- Print, Self Explaintry. s:gmatch('.-%[')()..'] = {' -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {. -- In the eggs example, this looks like; 'spam eggs[] = {' now .. -- concatenate... s:gsub('.-\n','',1) -- the input, with the first line removed. :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those, -- EG, '1, 2, 3, 4, 5, 6, ' :gsub(',%s+$','};') -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination ) end

function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end 

Explained

function g(s) print( -- Print, Self Explaintry. s:gmatch('.-%[')()..'] = {' -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {. -- In the eggs example, this looks like; 'spam eggs[] = {' now .. -- concatenate... s:gsub('.-\n','',1) -- the input, with the first line removed. :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those, -- EG, '1, 2, 3, 4, 5, 6, ' :gsub(',%s+$','};') -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination ) end 

##Lua, 121 Bytes. function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end

##Explained function g(s) print( -- Print, Self Explaintry. s:gmatch('.-%[')()..'] = {' -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {. -- In the eggs example, this looks like; 'spam eggs[] = {' now .. -- concatenate... s:gsub('.-\n','',1) -- the input, with the first line removed. :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those, -- EG, '1, 2, 3, 4, 5, 6, ' :gsub(',%s+$','};') -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination ) end

Lua, 121 Bytes.

function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end 

Explained

function g(s) print( -- Print, Self Explaintry. s:gmatch('.-%[')()..'] = {' -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {. -- In the eggs example, this looks like; 'spam eggs[] = {' now .. -- concatenate... s:gsub('.-\n','',1) -- the input, with the first line removed. :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those, -- EG, '1, 2, 3, 4, 5, 6, ' :gsub(',%s+$','};') -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination ) end 
Source Link
ATaco
  • 11.7k
  • 30
  • 82

##Lua, 121 Bytes. function g(s)print(s:gmatch('.-%[')()..'] = {'..s:gsub('.-\n','',1):gsub('.-([%d.-]+);\n?','%1, '):gsub(',%s+$','};'))end

##Explained function g(s) print( -- Print, Self Explaintry. s:gmatch('.-%[')()..'] = {' -- Find the 'header', match the first line's class and assignment name (everything up to the 'n]') and append that. Then, append ] = {. -- In the eggs example, this looks like; 'spam eggs[] = {' now .. -- concatenate... s:gsub('.-\n','',1) -- the input, with the first line removed. :gsub('.-([%d.-]+);\n?','%1, ') -- Then that chunk is searched, quite boringly, a number followed by a semicolon, and the entire string is replaced with an array of those, -- EG, '1, 2, 3, 4, 5, 6, ' :gsub(',%s+$','};') -- Replace the final ', ' (if any) with a single '};', finishing our terrifying combination ) end