-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0b02ef
commit 7173b43
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Data: 14/04/2024. De: Codewars. Link para o <a href=\"https://www.codewars.com/kata/55208f16ecb433c5c90001d2/train/python\">kata.</a>\n", | ||
"\n", | ||
"## Descrição\n", | ||
"Calcule o traço de uma matriz quadrada. Uma matriz quadrada tem n linhas e n colunas, onde n é qualquer número inteiro > 0. As entradas da matriz podem conter qualquer número de inteiros. A função deve retornar o traço calculado da matriz, ou nil/None se a matriz estiver vazia ou não for quadrada; você pode assumir que a entrada será válida de outra forma (no formato descrito abaixo).\n", | ||
"\n", | ||
"O traço de uma matriz quadrada n-por-n A é definido como a soma dos elementos na diagonal principal (a diagonal que vai do canto superior esquerdo ao canto inferior direito) de A.\n", | ||
"\n", | ||
"Uma matriz será definida como uma matriz de matrizes, onde a 1ª entrada representa a 1ª linha, a 2ª entrada a 2ª linha, e assim por diante.\n", | ||
"\n", | ||
"Por exemplo, o seguinte código...\n", | ||
"\n", | ||
"[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", | ||
"representa a matriz\n", | ||
"\n", | ||
"|1 2 3|\n", | ||
"|4 5 6|\n", | ||
"|7 8 9|\n", | ||
"que tem um traço de 1 + 5 + 9 = 15.\n", | ||
"\n", | ||
"Você pode ler mais sobre o traço de uma matriz nestas fontes:\n", | ||
"\n", | ||
"http://en.wikipedia.org/wiki/Trace_(linear_algebra)\n", | ||
"http://mathworld.wolfram.com/MatrixTrace.html\n", | ||
"Nota: Numpy está desativado." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Minha solução" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def trace(matrix):\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(trace([[1,2,3], [4,5,6], [7,8,9]])) # expects 15\n", | ||
"print(trace([[0,0], [0,0]])) # expects 0\n", | ||
"print(trace([[1]])) # expects 1\n", | ||
"print(trace([])) # expects None\n", | ||
"print(trace([[1,2,3], [4,5,6]])) # expects None" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters