This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__=2;print(1/( | |
- ~ - ~ - ~ - ~ - ~ - ~ - ~ - | |
~ __/ ~ - ~ - ~ - ~ - ~ - ~ - ~ | |
- __/ - ~ - __/ - ~ __/ ~ - __/__/ ~ - | |
~ __/ ~ - ~ __/ ~ - __/ - ~ - ~ __/ ~ | |
- __/ - ~ - __/ - ~ __/ ~ - __/__/__/ - | |
~ __/ ~ - ~ __/ ~ - __/ - __/ - ~ __/ ~ | |
- __/__/__/__/ ~ __/__/__/ ~ - __/__/__/ - | |
~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEC HEX CHR %d %x %a %l %u %w %p %g(5.2+) %s %c | |
0 00 - - - - - - - - - cntrl | |
1 01 - - - - - - - - - cntrl | |
2 02 - - - - - - - - - cntrl | |
3 03 - - - - - - - - - cntrl | |
4 04 - - - - - - - - - cntrl | |
5 05 - - - - - - - - - cntrl | |
6 06 - - - - - - - - - cntrl | |
7 07 - - - - - - - - - cntrl 7 "\a" = bell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------------------------------------------------------------------------------------- | |
-- AUTOMAGIC TABLES | |
---------------------------------------------------------------------------------------------------------------- | |
-- There is a well-known "standard" implementation of automagic tables at http://lua-users.org/wiki/AutomagicTables | |
-- | |
-- Unfortunately, that implementation behaves weirdly in some situations: | |
-- local a = AutomagicTable() | |
-- local x = a.b.c | |
-- local y = a.b.c | |
-- assert(x == y) -- assertion fails ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------------------------ | |
-- Module: null.lua | |
------------------------------------------------------------------------------------ | |
-- How to insert nils in an array? | |
-- Traditional approach is to appoint some Lua value as nil-replacement. | |
-- A function null(...) that swaps nils with itself may be a perfect candidate: | |
-- 1) It represents nil values inside an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- long_unsigned_integers.lua | |
--------------------------------------------------------------------------------------------------------- | |
-- LONG ARITHMETIC (non-negative integers of arbitrary length) | |
--------------------------------------------------------------------------------------------------------- | |
-- Compatible with Lua 5.1, Lua 5.2, Lua 5.3, LuaJIT | |
-- THIS MODULE WAS NOT OPTIMIZED FOR VERY LONG NUMBERS (multiplication has quadratic time complexity) | |
-- Usage: | |
-- local L = require("long_unsigned_integers") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local append, concat, floor, abs = table.insert, table.concat, math.floor, math.abs | |
local num = {'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', | |
'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'} | |
local tens = {'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'} | |
local bases = {{floor(1e18), ' quintillion'}, {floor(1e15), ' quadrillion'}, {floor(1e12), ' trillion'}, | |
{floor(1e9), ' billion'}, {1000000, ' million'}, {1000, ' thousand'}, {100, ' hundred'}} | |
local insert_word_AND = false -- 101 = "one hundred and one" / "one hundred one" | |
local function IntegerNumberInWords(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------------------------------- | |
-- This code snippet implements pseudo-random number generator | |
-- Output: 32-bit integers 0..4294967295 | |
-- Internal state (seed): 53 bits, can be read or write at any time | |
-- Good statistical properties of PRN sequence: | |
-- uniformity, | |
-- long period of 255 * 2^45 (approximately 2^53), | |
-- unpredictability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local write,D,L,select,tostring,ipairs,concat,execute,sub,gsub=io.write,{},8192,select,tostring,ipairs,table.concat,os.execute,string.sub,string.gsub | |
local T,E,I | |
T=io.read"*a" | |
T=string.match(T,"=(.-)$") or "" | |
T=gsub(T,"+"," ") | |
T=gsub(T,"%%(%x%x)",function (x) return string.char(tonumber(x,16)) end) | |
T=gsub(T,"^%s*=%s*","return ") | |
write(sub(T,1,L)) | |
write[[</TEXTAREA> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
--------------------------------------------------------------------------------------------------------------------------------------- | |
-- Converter from "source text" to "globals-backslashed source text" | |
--------------------------------------------------------------------------------------------------------------------------------------- | |
-- Reads Lua program from STDIN | |
-- Writes converted program to STDOUT (if the program is syntactically correct) | |
-- Writes parsing error to STDERR (if the program is not syntactically correct) | |
-- Usage (both Windows and Linux): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--~ How to run the benchmark: | |
--~ $ luajit sha256_for_LuaJIT.lua;luajit -O-narrow sha256_for_LuaJIT.lua | |
local table_concat, byte, char, string_rep, sub, floor, ceil, min, max = | |
table.concat, string.byte, string.char, string.rep, string.sub, math.floor, math.ceil, math.min, math.max | |
local b = require"bit" | |
local AND = b.band | |
local OR = b.bor |
OlderNewer