In Lua.
A classic.
local vars = {} | |
for i = 1, 50 do table.insert(vars, ("v%d"):format(i)) end | |
local all_vars, all_vals = table.concat(vars, ", "), "1" .. (", 2"):rep(#vars - 1) | |
local pathological_code = ([[ | |
local %s = %s | |
return function(get_all) | |
if get_all then return %s end | |
return v1 | |
end | |
]]):format(all_vars, all_vals, all_vars) |
#include <stdio.h> | |
#include <unistd.h> | |
#include <assert.h> | |
int main(int argc, char** argv) { | |
if (argc < 1) { | |
printf("Arguments: <program> {args}\n"); | |
return 1; | |
} |
// Solution to https://leetcode.com/problems/cheapest-flights-within-k-stops/description/ | |
// probably not the intended solution; uses an abridged Dijkstra to solve the much more general problem | |
// of finding all shortest paths to a given node using exactly k nodes | |
package main | |
import ( | |
"math" | |
"container/heap" | |
) |
-- Lookup table for format strings | |
local formats = {} | |
for i = 1, 17 do | |
formats[i] = ("%%.%dg"):format(i) | |
end | |
local function _number_to_string(num, min_digits, max_digits) | |
if min_digits > max_digits then | |
return | |
end |
-- Written by appgurueu, licensed under the MIT license | |
local function patch_tile_texture(tex) | |
if not (tex:match"^%[combine:" or tex:match"^%[inventorycube{") then | |
return | |
end | |
-- Prevent Minetest 5.5 from prepending "blank.png^" for 5.4 and older clients which don't support [png | |
-- See https://github.com/minetest/minetest/pull/12210 | |
return "(" .. tex .. ")" | |
end |
--[[ | |
Small, hacky Minetest utility to get rid of "unknown entities" as they are activated. Licensed under CC0. | |
Caveat: `/spawnentity <name>` will fail with "<name> failed to spawn" rather than "Cannot spawn an unknown entity." | |
for unknown entities as the unknown entity will immediately be removed inside `on_activate`. | |
]] | |
setmetatable(minetest.registered_entities, { | |
__index = function(_, name) | |
-- Default entity def if `minetest.registered_entities[name]` would otherwise be `nil` | |
-- Necessarily leads to `minetest.registered_entities[name]` being truthy for unknown entities as well |
-- Table helpers | |
table_ext= { | |
tablecopy = function(t) | |
return table.copy(t) | |
end, | |
count = function(table) | |
local count = 0 | |
for _ in pairs(table) do |
-- Use this to test waypoint capabilities | |
minetest.register_chatcommand( | |
"test_waypoints", | |
{ | |
description = "tests waypoint capabilities", | |
func = function(name) | |
local player = minetest.get_player_by_name(name) | |
minetest.chat_send_all( | |
"regular: " .. | |
player:hud_add { |
local min_lag = 1 -- in seconds | |
local min_times = 10 -- has to occur 10x | |
local times = 0 | |
minetest.register_globalstep(function(lag) | |
if lag < min_lag then | |
times = 0 | |
else | |
times = times + 1 | |
if times >= min_times then | |
minetest.request_shutdown("Server shutting down due to high latency (lag).") |