- Python té un sistema de tipus dinàmic.
- El tipus d'una variable depèn del seu valor en aquell moment.
- En programes grans, això incrementa els bugs i complica el seu manteniment.
- Des de fa un temps, els programes en Python es poden anotar amb tipus, de forma semblant al C++.
- Aquestes anotacions no tenen cap efecte en temps d'execució.
- Però hi ha eines que poden comprovar que no hi hagi errors de tipus (igual que fa el compilador de C++).
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
-- string to int conversion | |
s2i :: String -> Int | |
s2i = read | |
add :: String -> String | |
add = show . sum . (map s2i) . words | |
main = do | |
contents <- getContents | |
putStrLn $ add contents |
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
#!/usr/bin/env python3 |
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
#!/usr/bin/env python3 |
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
#include <iostream> | |
#include <vector> | |
#include <queue> | |
#include <utility> | |
#include <map> | |
using namespace std; | |
const int infinit = 999999999; |
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
from jutge import read | |
def dfs(G, u, y, vis): | |
if not vis[u]: | |
vis[u] = True | |
for v in G[u]: | |
if vis[y]: | |
return |
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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
using Graph = vector<vector<int>>; | |
void dfs (const Graph& G, int u, int y, vector<bool>& vis) { | |
vis[u] = true; |
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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
using Graf = vector<vector<int>>; // llistes d'adjacència | |
void dfs(const Graf& G, int u, int y, vector<bool>& vis) { | |
if (not vis[u]) { |
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
. . . . . 2 3 . 7 | |
. . . . . 6 4 5 . | |
1 . . 9 3 . . . . | |
. . . . 6 1 8 . . | |
. 4 8 . . . 5 6 . | |
. . 6 4 2 . . . . | |
. . . . 7 5 . . 8 | |
. 2 9 1 . . . . . | |
4 . 5 6 . . . . . |
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
# retorna x^n, amb n natural | |
def exp(x, n): | |
if n == 0: | |
return 1 | |
else: | |
return x * exp(x, n - 1) | |
# retorna x^n, amb n natural |
NewerOlder