Module:Mediants: Difference between revisions

Ganaram inukshuk (talk | contribs)
add sort function and convert-to-rational functions
Ganaram inukshuk (talk | contribs)
update code to be documentation
 
Line 1: Line 1:
-- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]]
local rat  = require("Module:Rational")
local rat  = require("Module:Rational")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local p = {}
local p = {}
-- Mediants consists of code used to find a tree of mediants, starting from a
-- set of starting ratios (default 1/1 and 1/0). Search can be by int limit,
-- depth, or a custom search function.
-- Ratios produced this way are a table consisting of the numerator and
-- denominator, which allows for non-simplified ratios to be represented.


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 32: Line 40:
)
)
end
end
--------------------------------------------------------------------------------
----------------------------- CONVERTER FUNCTIONS ------------------------------
--------------------------------------------------------------------------------
-- Converts ratios into the form defined by [[Module:Rational]], a table
-- consisting of its prime factorization.


-- Given a single ratio, as a table of two numbers, convert to rational and
-- Given a single ratio, as a table of two numbers, convert to rational and