typestar

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

  1. math.floor/ceil redondean; max/min toman cualquier cantidad.
  2. // divide al piso; math.type distingue entero de flotante.
  3. math.randomseed vuelve reproducibles las tiradas.

Palabras clave y builtins usados aquí

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.

Escribe este fragmento

Paso 1 de 2 en La biblioteca; paso 23 de 27 en Fundamentos del lenguaje.

← Anterior Siguiente →