La biblioteca math en Lua
floor y ceil, // y %, y un tipo numérico con dos caras.
-- The math library, and Lua's one number type wearing two faces.
print(math.floor(7.8), math.ceil(7.2))
print(math.max(12, 45, 3), math.min(12, 45, 3))
print("Root of 2: " .. string.format("%.4f", math.sqrt(2)))
-- Integers and floats coexist; // divides toward the floor.
print(7 / 2)
print(7 // 2)
print(7 % 3)
print(math.type(7), math.type(7.0))
-- Deterministic rolls come from a seeded generator.
math.randomseed(20)
print("Seeded roll: " .. math.random(1, 6))
Cómo funciona
math.floor/ceilredondean;max/mintoman cualquier cantidad.//divide al piso;math.typedistingue entero de flotante.math.randomseedvuelve reproducibles las tiradas.
Palabras clave y builtins usados aquí
print
El intento, en números
- Líneas
- 14
- Caracteres a escribir
- 468
- Tokens
- 91
- Ritmo de tres estrellas
- 65 tpm
Al ritmo de tres estrellas de 65 tokens por minuto, este intento toma unos 84 segundos.
Paso 1 de 2 en La biblioteca; paso 23 de 27 en Fundamentos del lenguaje.