Ir para conteúdo

Pesquisar na Comunidade

Mostrando resultados para as tags ''recursividade''.



Mais opções de pesquisa

  • Pesquisar por Tags

    Digite tags separadas por vírgulas
  • Pesquisar por Autor

Tipo de Conteúdo


Fóruns

  • A Cidade OTBR
    • OTServ Brasil
    • Atendimento
    • Taverna
  • Projetos Open Source
    • Canary
    • OTServBR-Global
    • Mehah OTClient
    • MyAAC
  • OpenTibia
    • Notícias e Discussões
    • Suporte - Dúvidas, Bugs, Erros
    • Downloads
    • Tutoriais
    • Show-Off
  • Outros
    • Design

Encontrado 2 registros

  1. S.O.M.A ~ Sistema de Matrizes

    S.O.M.A System of Matrixes Autor: PeJuGe Comentário: [spoiler=Comentário]Este sistema é uma exclusividade OTNet (como todos os meus scripts até o instante) e busca a implementação de matrizes em Lua por meio da utilização de funções básicas. Como são 14 Funções não explicarei-as passo-a-passo, apenas postarei o script. Caso tenha alguma dúvida consulte o índice no início do script, em caso de persistência da dúvida poste-a abaixo. Script: --[[ PeJuGe(2010) . S.O.M.A 1.0 ~ System of Matrix DON'T REMOVE THE CREDITS Exclusive For www.otserv.com.br More Info: http://forums.otserv.com.br/showthread.php?p=1037456#post1037456 + matrix.correct(m) * Returnes true for correct matrix or false. + matrix.sqr(m) * Returns true for square matrix or false. + matrix.lines(m) * Returns the number of lines. + matrix.columns(m) * Returns the number of columns. + matrix.addline(l1, l2) * Returns the added lines. + matrix.column(m, n) * Returns the selected column. + matrix.reverse(m) * Returns reversed matrix. + matrix.addline(l1, l2) * Returns the sun of l1 and l2. + matrix.addcolunm(m1, n1, m2, n2) * Returns the sun of columns n1 from m1 and n2 from m2. + matrix.add * Returns the sun of matrixes. + matrix.mulline(l1, l2) * Returns the multiplication of l1 and l2. + matrix.mul(m1, m2) * Returns multiplicated matrixes. + matrix.concat(m) * Returns concated matrix. + matrix.det(m) * Returns the det of matrix (At moment alone smaller or equal than 3). ]]-- local matrix = {} function matrix.correct(m, r) r = r or 1 return #m >= r and #m[r] == #m[1] and matrix.correct(m, r + 1) or #m < r end function matrix.sqr(m) return matrix.correct(m) and #m == #m[1] and #m end function matrix.lines(m) return matrix.correct(m) and #m end function matrix.columns(m) return matrix.correct(m) and #m[1] end function matrix.column(m, n, r) r = r or {} r[#r + 1] = m[#r + 1][n] return #r == #m and r or matrix.column(m, n, r) end function matrix.reverse(m, r) r = r or {} r[#r + 1] = matrix.column(m, #r + 1) return #r == #m[1] and r or matrix.reverse(m, r) end function matrix.addline(l1, l2, r) r = r or {} r[#r + 1] = l1[#r + 1] + l2[#r + 1] return #l1 == #r and r or matrix.addline(l1, l2, r) end function matrix.addcolumn(m1, n1, m2, n2, r) return matrix.addline(matrix.column(m1, n1), matrix.column(m2, n2)) end function matrix.add(m1, m2, r) r = r or {} r[#r + 1] = matrix.addline(m1[#r + 1], m2[#r + 1]) return #m1 == #r and r or matrix.sun(m1, m2, r) end function matrix.mulline(l1, l2, r) r = r or {0, 0} r[1], r[2] = r[1] + l1[r[2] + 1] * l2[r[2] + 1], r[2] + 1 return r[2] == #l1 and r[1] or matrix.mulline(l1, l2, r) end function matrix.mul(m1, m2, r, n) m2, r, n = not r and matrix.reverse(m2) or m2, r or {}, n or 1 r[#r + 1] = n ~= #r and {} or nil r[#r][#r[#r] + 1] = matrix.mulline(m1[#r], m2[#r[#r] + 1]) n = #m2 == #r[#r] and n + 1 or n return n > #m1 and r or matrix.mul(m1, m2, r, n) end function matrix.concat(m, r) r = r or {} r[#r + 1] = table.concat(m[#r + 1], " ") return #m == #r and table.concat(r, "\n") or matrix.concat(m, r) end function matrix.det(m) sqr = matrix.sqr(m) return matrix.sqr and ( sqr == 1 and m[1][1] or sqr == 2 and m[1][1] * m[2][2] - m[1][2] * m[2][1] or sqr == 3 and m[1][1] * m[2][2] * m[3][3] + m[1][2] * m[2][3] * m[3][1] + m[1][3] * m[2][1] * m[3][2] - (m[3][1] * m[2][2] * m[1][3] + m[3][2] * m[2][3] * m[1][1] + m[3][3] * m[2][1] * m[1][2]) or false) or false end Construindo uma matriz: Coloque as uma tabela para a matriz, sendo que cada linha é representada por uma tabela única: local matrix = { --> matriz quadrada {2, 3}, {9, 8} } local matrix2 = { -- > matriz não quadrada {2, 3, 4}, {1, 54, 9} } local matrix3 = { -- > matrix inexistente {3, 1, 2}, {1}, {13, 2} } --Observe como coletar dados print(matrix[1][1]) --> 2 print(matrix[1][2]) -- > 3 print(matrix[2][1]) -- > 9 print(matrix[2][2]) -- > 8 Deste modo segue o padrão Aij com A[j] (quem conhece matemática sabe do que estou falando). Fico devendo nessa Lib determinação de det para tabelas de ordem maior que quatro. Há ainda a utilização de matrizes com sistemas lineares... Obrigado por ler meu tópico, caso haja alguma dúvida, reclamação ou sugestão favor postar abaixo. Atenciosamente, PeJuGe.
  2. 7 Funções

    7 Funções Autor: PeJuGe Comentário: [spoiler=Comentário]Estas são funções que eu já postei em sua maioria e estou postando novamente mas agora melhoradas, sendo nova apenas math.factorial. Não explicarei, apenas postarei o script. Caso tenha alguma dúvida consulte o índice no início do script, em caso de persistência da dúvida poste-a abaixo. Script: --[[ PeJuGe(2010) . 7 Funções DON'T REMOVE THE CREDITS Exclusive For www.otserv.com.br More Info: http://forums.otserv.com.br/showthread.php?p=1037724#post1037724 + string.toup(txt) * Returns the first letter upped. + getlocation(table, m) * Returns the location of a value in a table + math.textreme(table, value) * Returns the maximum and minimum value + math.multiple(value, param) * Returns true or false + math.tmultiple(table, param) * Returns the multiples of param from table + math.approx(value) * Returns the nearest number + math.factorial(value) * Returns the factored number ]]-- function string.toup(txt) return string.upper(txt:sub(1, 1)) .. txt:sub(2) end function getlocation(table, m, r) r = r or 1 return #table >= r and table[r] ~= m and getlocation(table, m, r + 1) or table[r] == m and r end function math.textreme(table, value, r) r = r or {math.huge, -math.huge, 1} r[1], r[2], r[3] = table[r[3]] < r[1] and table[r[3]] or r[1], table[r[3]] > r[1] and table[r[3]] or r[2], r[3] + 1 return r[3] == #table + 1 and {min = r[1], max = r[2]} or math.textreme(table, value, r) end function math.multiple(value, param) return value % param == 0 end function math.tmultiple(table, param, r) r = r or {{}, 1} r[1][#r[1] + 1], r[2] = math.multiple(table[r[2]], param) and table[r[2]] or nil, r[2] + 1 return r[2] == #table + 1 and r[1] or math.tmultiple(table, param, r) end function math.approx(value) return math.floor(value + 0.5) > math.floor(value) and math.ceil(value) or math.floor(value) end function math.factorial(n) return math.floor(n) > 1 and (math.floor(n) * math.factorial (n-1)) or 1 end Bom, obrigado por ler meu tópico. Caso tenha alguma dúvida, reclamação ou sugestão, favor postar abaixo, pois sua dúvida pode pertencer também a outra pessoa. Atenciosamente, PeJuGe
×